On Jun 11, 2009, at 10:27 AM, Walter Cruz wrote:
> But I /did/ manage to get @cache.cache to work by supplying a
> data_dir:
>
> @cache.cache('foobar2', type='file',
> data_dir='./data/cache',
> expire=3600)
>
> Yes, looks like the problem is that the data_dir setting from teh
> ini file is being ignored.. is possible to use
> datadir=pylons.config.whateverthatidontremember['data_dir'] but this
> is not clean ;)
I can't seem to reproduce this. It works fine here.
Can you indicate where you got 'cache' from? And what method you're
decorating?
Here's the recommend method for using the Beaker cache object.
1) Turn off the CacheMiddleware in your config/middleware.py
2) In your lib/app_globals.py add the following imports:
from pylons import config
from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options
3) In lib/app_globals.py, add the following to the Globals __init__
method:
self.cache = CacheManager(**parse_cache_config_options(config))
4) In the controller action of your choice, find something that takes
a long time to generate, and decorate with the cache method, for
example in one of my own projects:
from pylons import app_globals
def load_cases(tag):
@app_globals.cache.region('short_term')
def fetch_cases(tag):
# Collect recent stats of interest
# Show recently filed cases
....
return (recent_cases, trials)
return fetch_cases(tag)
Note that merely importing the module will not cause the decorator to
run. This is a *very important* distinction between having the use of
the decorator on a nested function, than one that will be immediately
evaluated on import. When using the cache.cache or cache.region
decorator inside a Pylons controller method, you should also nest it
around the expensive bit as the example above, to prevent premature
execution of the decorator function (ie, running it when the
app_globals isn't actually setup).
This could be affecting the use causing the problem, if you're using
the pylons.cache reference, because it might not actually be fully
setup yet (thus missing the data_dir option). If you're directly
decorating a controller method, move it to a nested function.
The way I recommend here will also be default going forward in Pylons
as it avoids the unnecessary constant CacheMiddleware execution step,
when the cache object should be always available anyways in the app.
Cheers,
Ben
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---