Permalink
Browse files

Added key_length cache param for beaker 1.6+.

  • Loading branch information...
1 parent 4d96cac commit 3ef17d10e78c435b0051699bf29a608375151292 @mmerickel mmerickel committed Nov 14, 2011
Showing with 33 additions and 20 deletions.
  1. +6 −0 docs/index.rst
  2. +25 −19 pyramid_beaker/__init__.py
  3. +2 −1 pyramid_beaker/tests.py
View
@@ -151,12 +151,18 @@ Inherited region settings
The following optional region settings inherit from the main cache
configuration or default as specified:
+``data_dir``
+ Inherits if specified.
+
``enabled``
Inherits or defaults to True.
``expire``
Inherits or defaults to 60 seconds.
+``key_length``
+ Inherits or defaults to 250 characters.
+
``lock_dir``
Inherits if specified.
View
@@ -2,6 +2,7 @@
from beaker import cache
from beaker.session import SessionObject
+from beaker.util import coerce_cache_params
from beaker.util import coerce_session_params
from pyramid.interfaces import ISession
@@ -136,25 +137,30 @@ def set_cache_regions_from_settings(settings):
if key.startswith(prefix):
name = key.split(prefix)[1].strip()
cache_settings[name] = settings[key].strip()
- if cache_settings['regions']:
- for region in cache_settings['regions'].split(','):
- region = region.strip()
- region_settings = {}
- for key, value in cache_settings.items():
- if key.startswith(region):
- region_settings[key.split('.')[1]] = value
- region_settings['expire'] = int(region_settings.get('expire', 60))
- if 'enabled' not in region_settings:
- enabled_value_source = cache_settings
- else:
- enabled_value_source = region_settings
- region_settings['enabled'] = enabled_value_source.get('enabled', 'true').lower() == 'true'
- if 'lock_dir' not in region_settings:
- region_settings['lock_dir'] = cache_settings.get('lock_dir')
- if 'type' not in region_settings:
- region_settings['type'] = cache_settings.get('type', 'memory')
- if 'url' not in region_settings:
- region_settings['url'] = cache_settings.get('url')
+ coerce_cache_params(cache_settings)
+
+ if 'enabled' not in cache_settings:
+ cache_settings['enabled'] = True
+
+ regions = cache_settings['regions']
+ if regions:
+ for region in regions:
+ if not region: continue
+ region_settings = {
+ 'data_dir': cache_settings.get('data_dir'),
+ 'lock_dir': cache_settings.get('lock_dir'),
+ 'expire': cache_settings.get('expire', 60),
+ 'enabled': cache_settings['enabled'],
+ 'key_length': cache_settings.get('key_length', 250),
+ 'type': cache_settings.get('type'),
+ 'url': cache_settings.get('url'),
+ }
+ region_prefix = '%s.' % region
+ region_len = len(region_prefix)
+ for key in cache_settings.keys():
+ if key.startswith(region_prefix):
+ region_settings[key[region_len:]] = cache_settings.pop(key)
+ coerce_cache_params(region_settings)
cache.cache_regions[region] = region_settings
def includeme(config):
View
@@ -262,7 +262,8 @@ def test_add_cache_single_region_no_expire(self):
default_term = beaker.cache.cache_regions.get('default_term')
self.assertEqual(default_term,
{'url': None, 'expire': 60, 'type': 'memory',
- 'lock_dir': None, 'enabled': True})
+ 'lock_dir': None, 'data_dir': None, 'enabled': True,
+ 'key_length': 250,})
def test_add_cache_multiple_region(self):
from pyramid_beaker import set_cache_regions_from_settings

0 comments on commit 3ef17d1

Please sign in to comment.