set default for caching to false

ref #1689

* set default settigns in settings.py to False for
  - LOAD_CONTENT_CACHE
  - CACHE_CONTENT
* remove AUTORELOAD_IGNORE_CACHE and add deprecation warning
* update settings.rst to reflect the new default values
* update test_cache to enable caching options
This commit is contained in:
derwinlu 2015-06-06 20:07:12 +02:00
commit db59c16f42
4 changed files with 24 additions and 29 deletions

View file

@ -204,7 +204,7 @@ Setting name (followed by default value, if any)
``SLUGIFY_SOURCE = 'title'`` Specifies where you want the slug to be automatically generated ``SLUGIFY_SOURCE = 'title'`` Specifies where you want the slug to be automatically generated
from. Can be set to ``title`` to use the 'Title:' metadata tag or from. Can be set to ``title`` to use the 'Title:' metadata tag or
``basename`` to use the article's file name when creating the slug. ``basename`` to use the article's file name when creating the slug.
``CACHE_CONTENT = True`` If ``True``, save content in a cache file. ``CACHE_CONTENT = False`` If ``True``, saves content in caches.
See :ref:`reading_only_modified_content` for details about caching. See :ref:`reading_only_modified_content` for details about caching.
``CONTENT_CACHING_LAYER = 'reader'`` If set to ``'reader'``, save only the raw content and metadata ``CONTENT_CACHING_LAYER = 'reader'`` If set to ``'reader'``, save only the raw content and metadata
returned by readers. If set to ``'generator'``, save processed returned by readers. If set to ``'generator'``, save processed
@ -212,9 +212,7 @@ Setting name (followed by default value, if any)
``CACHE_PATH = 'cache'`` Directory in which to store cache files. ``CACHE_PATH = 'cache'`` Directory in which to store cache files.
``GZIP_CACHE = True`` If ``True``, use gzip to (de)compress the cache files. ``GZIP_CACHE = True`` If ``True``, use gzip to (de)compress the cache files.
``CHECK_MODIFIED_METHOD = 'mtime'`` Controls how files are checked for modifications. ``CHECK_MODIFIED_METHOD = 'mtime'`` Controls how files are checked for modifications.
``LOAD_CONTENT_CACHE = True`` If ``True``, load unmodified content from cache. ``LOAD_CONTENT_CACHE = False`` If ``True``, load unmodified content from caches.
``AUTORELOAD_IGNORE_CACHE = False`` If ``True``, do not load content cache in autoreload mode
when the settings file changes.
``WRITE_SELECTED = []`` If this list is not empty, **only** output files with their paths ``WRITE_SELECTED = []`` If this list is not empty, **only** output files with their paths
in this list are written. Paths should be either absolute or relative in this list are written. Paths should be either absolute or relative
to the current Pelican working directory. For possible use cases see to the current Pelican working directory. For possible use cases see

View file

@ -101,6 +101,11 @@ class Pelican(object):
'PAGE_LANG_URL'): 'PAGE_LANG_URL'):
logger.warning("%s = '%s'", setting, self.settings[setting]) logger.warning("%s = '%s'", setting, self.settings[setting])
if self.settings.get('AUTORELOAD_IGNORE_CACHE'):
logger.warning('Found deprecated `AUTORELOAD_IGNORE_CACHE` in '
'settings. Use --ignore-cache instead.')
self.settings.pop('AUTORELOAD_IGNORE_CACHE')
if self.settings.get('ARTICLE_PERMALINK_STRUCTURE', False): if self.settings.get('ARTICLE_PERMALINK_STRUCTURE', False):
logger.warning('Found deprecated `ARTICLE_PERMALINK_STRUCTURE` in' logger.warning('Found deprecated `ARTICLE_PERMALINK_STRUCTURE` in'
' settings. Modifying the following settings for' ' settings. Modifying the following settings for'
@ -381,10 +386,6 @@ def main():
print(' --- AutoReload Mode: Monitoring `content`, `theme` and' print(' --- AutoReload Mode: Monitoring `content`, `theme` and'
' `settings` for changes. ---') ' `settings` for changes. ---')
def _ignore_cache(pelican_obj):
if pelican_obj.settings['AUTORELOAD_IGNORE_CACHE']:
pelican_obj.settings['LOAD_CONTENT_CACHE'] = False
while True: while True:
try: try:
# Check source dir for changed files ending with the given # Check source dir for changed files ending with the given
@ -393,12 +394,9 @@ def main():
# have changed, no matter what extension the filenames # have changed, no matter what extension the filenames
# have. # have.
modified = {k: next(v) for k, v in watchers.items()} modified = {k: next(v) for k, v in watchers.items()}
original_load_cache = settings['LOAD_CONTENT_CACHE']
if modified['settings']: if modified['settings']:
pelican, settings = get_instance(args) pelican, settings = get_instance(args)
original_load_cache = settings['LOAD_CONTENT_CACHE']
_ignore_cache(pelican)
# Adjust static watchers if there are any changes # Adjust static watchers if there are any changes
new_static = settings.get("STATIC_PATHS", []) new_static = settings.get("STATIC_PATHS", [])
@ -435,8 +433,6 @@ def main():
'theme.') 'theme.')
pelican.run() pelican.run()
# restore original caching policy
pelican.settings['LOAD_CONTENT_CACHE'] = original_load_cache
except KeyboardInterrupt: except KeyboardInterrupt:
logger.warning("Keyboard interrupt, quitting.") logger.warning("Keyboard interrupt, quitting.")

View file

@ -123,13 +123,12 @@ DEFAULT_CONFIG = {
'SLUG_SUBSTITUTIONS': (), 'SLUG_SUBSTITUTIONS': (),
'INTRASITE_LINK_REGEX': '[{|](?P<what>.*?)[|}]', 'INTRASITE_LINK_REGEX': '[{|](?P<what>.*?)[|}]',
'SLUGIFY_SOURCE': 'title', 'SLUGIFY_SOURCE': 'title',
'CACHE_CONTENT': True, 'CACHE_CONTENT': False,
'CONTENT_CACHING_LAYER': 'reader', 'CONTENT_CACHING_LAYER': 'reader',
'CACHE_PATH': 'cache', 'CACHE_PATH': 'cache',
'GZIP_CACHE': True, 'GZIP_CACHE': True,
'CHECK_MODIFIED_METHOD': 'mtime', 'CHECK_MODIFIED_METHOD': 'mtime',
'LOAD_CONTENT_CACHE': True, 'LOAD_CONTENT_CACHE': False,
'AUTORELOAD_IGNORE_CACHE': False,
'WRITE_SELECTED': [], 'WRITE_SELECTED': [],
'FORMATTED_FIELDS': ['summary'], 'FORMATTED_FIELDS': ['summary'],
} }

View file

@ -28,11 +28,18 @@ class TestCache(unittest.TestCase):
def tearDown(self): def tearDown(self):
rmtree(self.temp_cache) rmtree(self.temp_cache)
def _get_cache_enabled_settings(self):
settings = get_settings(filenames={})
settings['CACHE_CONTENT'] = True
settings['LOAD_CONTENT_CACHE'] = True
settings['CACHE_PATH'] = self.temp_cache
return settings
@unittest.skipUnless(MagicMock, 'Needs Mock module') @unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_article_object_caching(self): def test_article_object_caching(self):
"""Test Article objects caching at the generator level""" """Test Article objects caching at the generator level"""
settings = get_settings(filenames={}) settings = self._get_cache_enabled_settings()
settings['CACHE_PATH'] = self.temp_cache
settings['CONTENT_CACHING_LAYER'] = 'generator' settings['CONTENT_CACHING_LAYER'] = 'generator'
settings['DEFAULT_DATE'] = (1970, 1, 1) settings['DEFAULT_DATE'] = (1970, 1, 1)
settings['READERS'] = {'asc': None} settings['READERS'] = {'asc': None}
@ -60,8 +67,7 @@ class TestCache(unittest.TestCase):
@unittest.skipUnless(MagicMock, 'Needs Mock module') @unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_article_reader_content_caching(self): def test_article_reader_content_caching(self):
"""Test raw article content caching at the reader level""" """Test raw article content caching at the reader level"""
settings = get_settings(filenames={}) settings = self._get_cache_enabled_settings()
settings['CACHE_PATH'] = self.temp_cache
settings['READERS'] = {'asc': None} settings['READERS'] = {'asc': None}
generator = ArticlesGenerator( generator = ArticlesGenerator(
@ -85,8 +91,7 @@ class TestCache(unittest.TestCase):
"""Test that all the articles are read again when not loading cache """Test that all the articles are read again when not loading cache
used in --ignore-cache or autoreload mode""" used in --ignore-cache or autoreload mode"""
settings = get_settings(filenames={}) settings = self._get_cache_enabled_settings()
settings['CACHE_PATH'] = self.temp_cache
settings['READERS'] = {'asc': None} settings['READERS'] = {'asc': None}
generator = ArticlesGenerator( generator = ArticlesGenerator(
@ -108,10 +113,9 @@ class TestCache(unittest.TestCase):
@unittest.skipUnless(MagicMock, 'Needs Mock module') @unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_page_object_caching(self): def test_page_object_caching(self):
"""Test Page objects caching at the generator level""" """Test Page objects caching at the generator level"""
settings = get_settings(filenames={}) settings = self._get_cache_enabled_settings()
settings['CACHE_PATH'] = self.temp_cache
settings['PAGE_PATHS'] = ['TestPages']
settings['CONTENT_CACHING_LAYER'] = 'generator' settings['CONTENT_CACHING_LAYER'] = 'generator'
settings['PAGE_PATHS'] = ['TestPages']
settings['READERS'] = {'asc': None} settings['READERS'] = {'asc': None}
generator = PagesGenerator( generator = PagesGenerator(
@ -134,8 +138,7 @@ class TestCache(unittest.TestCase):
@unittest.skipUnless(MagicMock, 'Needs Mock module') @unittest.skipUnless(MagicMock, 'Needs Mock module')
def test_page_reader_content_caching(self): def test_page_reader_content_caching(self):
"""Test raw page content caching at the reader level""" """Test raw page content caching at the reader level"""
settings = get_settings(filenames={}) settings = self._get_cache_enabled_settings()
settings['CACHE_PATH'] = self.temp_cache
settings['PAGE_PATHS'] = ['TestPages'] settings['PAGE_PATHS'] = ['TestPages']
settings['READERS'] = {'asc': None} settings['READERS'] = {'asc': None}
@ -160,8 +163,7 @@ class TestCache(unittest.TestCase):
"""Test that all the pages are read again when not loading cache """Test that all the pages are read again when not loading cache
used in --ignore_cache or autoreload mode""" used in --ignore_cache or autoreload mode"""
settings = get_settings(filenames={}) settings = self._get_cache_enabled_settings()
settings['CACHE_PATH'] = self.temp_cache
settings['PAGE_PATHS'] = ['TestPages'] settings['PAGE_PATHS'] = ['TestPages']
settings['READERS'] = {'asc': None} settings['READERS'] = {'asc': None}