Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for having no expiry on a cache region. #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.8.1 (Unreleased)
------------------

- Added support for cache regions with no expiry

0.8 (2013-06-28)
----------------

Expand Down
7 changes: 7 additions & 0 deletions pyramid_beaker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ def set_cache_regions_from_settings(settings):
if key.startswith(prefix):
name = key.split(prefix)[1].strip()
cache_settings[name] = settings[key].strip()
if ('expire' in cache_settings
and isinstance(cache_settings['expire'], basestring)
and cache_settings['expire'].lower() in ['none', 'no']):
cache_settings['expire'] = None
coerce_cache_params(cache_settings)

if 'enabled' not in cache_settings:
Expand All @@ -165,6 +169,9 @@ def set_cache_regions_from_settings(settings):
for key in list(cache_settings.keys()):
if key.startswith(region_prefix):
region_settings[key[region_len:]] = cache_settings.pop(key)
if (isinstance(region_settings['expire'], basestring)
and region_settings['expire'].lower() in ['none', 'no']):
region_settings['expire'] = None
coerce_cache_params(region_settings)
cache.cache_regions[region] = region_settings

Expand Down
11 changes: 11 additions & 0 deletions pyramid_beaker/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,17 @@ def test_add_cache_single_region_no_expire(self):
'lock_dir': None, 'data_dir': None, 'enabled': True,
'key_length': 250,})

def test_add_cache_single_region_never_expire(self):
from pyramid_beaker import set_cache_regions_from_settings
import beaker
settings = self._set_settings()
beaker.cache.cache_regions = {}
settings['cache.regions'] = 'default_term'
settings['cache.default_term.expire'] = 'None'
set_cache_regions_from_settings(settings)
default_term = beaker.cache.cache_regions.get('default_term')
self.assertIsNone(default_term['expire'])

def test_add_cache_multiple_region(self):
from pyramid_beaker import set_cache_regions_from_settings
import beaker
Expand Down