Show More
@@ -145,60 +145,6 b' def session_factory_from_settings(settin' | |||
|
145 | 145 | return BeakerSessionFactoryConfig(**options) |
|
146 | 146 | |
|
147 | 147 | |
|
148 | def set_cache_regions_from_settings(settings): | |
|
149 | """ Add cache support to the Pylons application. | |
|
150 | ||
|
151 | The ``settings`` passed to the configurator are used to setup | |
|
152 | the cache options. Cache options in the settings should start | |
|
153 | with either 'beaker.cache.' or 'cache.'. | |
|
154 | ||
|
155 | """ | |
|
156 | cache_settings = {'regions': []} | |
|
157 | for key in settings.keys(): | |
|
158 | for prefix in ['beaker.cache.', 'cache.']: | |
|
159 | if key.startswith(prefix): | |
|
160 | name = key.split(prefix)[1].strip() | |
|
161 | cache_settings[name] = settings[key].strip() | |
|
162 | ||
|
163 | if ('expire' in cache_settings | |
|
164 | and isinstance(cache_settings['expire'], basestring) | |
|
165 | and cache_settings['expire'].lower() in ['none', 'no']): | |
|
166 | cache_settings['expire'] = None | |
|
167 | ||
|
168 | coerce_cache_params(cache_settings) | |
|
169 | ||
|
170 | if 'enabled' not in cache_settings: | |
|
171 | cache_settings['enabled'] = True | |
|
172 | ||
|
173 | regions = cache_settings['regions'] | |
|
174 | if regions: | |
|
175 | for region in regions: | |
|
176 | if not region: | |
|
177 | continue | |
|
178 | ||
|
179 | region_settings = { | |
|
180 | 'data_dir': cache_settings.get('data_dir'), | |
|
181 | 'lock_dir': cache_settings.get('lock_dir'), | |
|
182 | 'expire': cache_settings.get('expire', 60), | |
|
183 | 'enabled': cache_settings['enabled'], | |
|
184 | 'key_length': cache_settings.get('key_length', 250), | |
|
185 | 'type': cache_settings.get('type'), | |
|
186 | 'url': cache_settings.get('url'), | |
|
187 | } | |
|
188 | region_prefix = '%s.' % region | |
|
189 | region_len = len(region_prefix) | |
|
190 | for key in list(cache_settings.keys()): | |
|
191 | if key.startswith(region_prefix): | |
|
192 | region_settings[key[region_len:]] = cache_settings.pop(key) | |
|
193 | ||
|
194 | if (isinstance(region_settings['expire'], basestring) | |
|
195 | and region_settings['expire'].lower() in ['none', 'no']): | |
|
196 | region_settings['expire'] = None | |
|
197 | coerce_cache_params(region_settings) | |
|
198 | cache.cache_regions[region] = region_settings | |
|
199 | ||
|
200 | ||
|
201 | 148 | def includeme(config): |
|
202 | 149 | session_factory = session_factory_from_settings(config.registry.settings) |
|
203 | 150 | config.set_session_factory(session_factory) |
|
204 | set_cache_regions_from_settings(config.registry.settings) |
General Comments 0
You need to be logged in to leave comments.
Login now