Beaker 1.3.1 and MissingCacheParameter

16 views
Skip to first unread message

Walter Cruz

unread,
Jun 9, 2009, 10:46:30 AM6/9/09
to pylons-...@googlegroups.com
Hi! I upgraded to Beaker 1.3.1 and now I'm getitng
MissingCacheParameter

My full traceback

URL: http://127.0.0.1:5001/
File '/home/walter/.virtualenvs/pylons/lib/python2.5/site-packages/WebError-0.10.1-py2.5.egg/weberror/evalexception.py', line 431 in respond
app_iter = self.application(environ, detect_start_response)
File '/usr/lib/python2.5/site-packages/ToscaWidgets-0.9.3-py2.5.egg/tw/core/middleware.py', line 36 in __call__
return self.wsgi_app(environ, start_response)
File '/usr/lib/python2.5/site-packages/ToscaWidgets-0.9.3-py2.5.egg/tw/core/middleware.py', line 59 in wsgi_app
resp = req.get_response(self.application)
File 'build/bdist.linux-i686/egg/webob/__init__.py', line 1325 in get_response
File 'build/bdist.linux-i686/egg/webob/__init__.py', line 1293 in call_application
File '/usr/lib/python2.5/site-packages/ToscaWidgets-0.9.3-py2.5.egg/tw/core/resource_injector.py', line 67 in _injector
resp = req.get_response(app)
File 'build/bdist.linux-i686/egg/webob/__init__.py', line 1325 in get_response
File 'build/bdist.linux-i686/egg/webob/__init__.py', line 1293 in call_application
File '/usr/lib/python2.5/site-packages/Paste-1.7.2-py2.5.egg/paste/gzipper.py', line 38 in __call__
response.gzip_start_response)
File '/home/walter/.virtualenvs/pylons/lib/python2.5/site-packages/Beaker-1.3.1-py2.5.egg/beaker/middleware.py', line 70 in __call__
return self.app(environ, start_response)
File '/home/walter/.virtualenvs/pylons/lib/python2.5/site-packages/Beaker-1.3.1-py2.5.egg/beaker/middleware.py', line 149 in __call__
return self.wrap_app(environ, session_start_response)
File '/usr/lib/python2.5/site-packages/AuthKit-0.4.2-py2.5.egg/authkit/authenticate/__init__.py', line 324 in __call__
return self.app(environ, start_response)
File '/usr/lib/python2.5/site-packages/AuthKit-0.4.2-py2.5.egg/authkit/authenticate/cookie.py', line 396 in __call__
return self.app(environ, cookie_setting_start_response)
File '/usr/lib/python2.5/site-packages/AuthKit-0.4.2-py2.5.egg/authkit/authenticate/open_id.py', line 476 in __call__
return self.app(environ, start_response)
File '/usr/lib/python2.5/site-packages/AuthKit-0.4.2-py2.5.egg/authkit/authenticate/open_id.py', line 230 in __call__
return self.app(environ, start_response)
File '/usr/lib/python2.5/site-packages/AuthKit-0.4.2-py2.5.egg/authkit/authenticate/multi.py', line 85 in __call__
app_iter = app(environ, start_response)
File '/usr/lib/python2.5/site-packages/AuthKit-0.4.2-py2.5.egg/authkit/authenticate/multi.py', line 55 in app
return self.default(environ, find)
File '/usr/lib/python2.5/site-packages/AuthKit-0.4.2-py2.5.egg/authkit/authenticate/__init__.py', line 314 in __call__
return self.app(environ, start_response)
File '/usr/lib/python2.5/site-packages/Paste-1.7.2-py2.5.egg/paste/httpexceptions.py', line 636 in __call__
return self.application(environ, start_response)
File '/home/walter/.virtualenvs/pylons/lib/python2.5/site-packages/Routes-1.10.3-py2.5.egg/routes/middleware.py', line 130 in __call__
response = self.app(environ, start_response)
File '/home/walter/.virtualenvs/pylons/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/wsgiapp.py', line 125 in __call__
response = self.dispatch(controller, environ, start_response)
File '/home/walter/.virtualenvs/pylons/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/wsgiapp.py', line 324 in dispatch
return controller(environ, start_response)
File '/home/walter/devel/pylons/artigos/artigos/lib/base.py', line 28 in __call__
return WSGIController.__call__(self, environ, start_response)
File '/home/walter/.virtualenvs/pylons/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py', line 221 in __call__
response = self._dispatch_call()
File '/home/walter/.virtualenvs/pylons/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py', line 172 in _dispatch_call
response = self._inspect_call(func)
File '/home/walter/.virtualenvs/pylons/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py', line 107 in _inspect_call
result = self._perform_call(func, args)
File '/home/walter/.virtualenvs/pylons/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py', line 60 in _perform_call
return func(**args)
File '<string>', line 2 in view
File '/home/walter/.virtualenvs/pylons/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/decorators/cache.py', line 97 in wrapper
my_cache = pylons.cache.get_cache(namespace, **b_kwargs)
File '/home/walter/.virtualenvs/pylons/lib/python2.5/site-packages/Beaker-1.3.1-py2.5.egg/beaker/cache.py', line 187 in get_cache
return self.caches.setdefault(name + str(kw), Cache(name, **kw))
File '/home/walter/.virtualenvs/pylons/lib/python2.5/site-packages/Beaker-1.3.1-py2.5.egg/beaker/cache.py', line 104 in __init__
self.namespace = cls(namespace, **nsargs)
File '/home/walter/.virtualenvs/pylons/lib/python2.5/site-packages/Beaker-1.3.1-py2.5.egg/beaker/container.py', line 485 in __init__
raise MissingCacheParameter("data_dir or file_dir is required")
MissingCacheParameter: data_dir or file_dir is required

Can someone help me?

--
[]'
- Walter
waltercruz.com

Mike Orr

unread,
Jun 10, 2009, 1:53:26 PM6/10/09
to pylons-...@googlegroups.com

This is the same error I reported yesterday, but I haven't seen any
diagnosis yet. I'll have to disable @beaker_cache in the meantime.

--
Mike Orr <slugg...@gmail.com>

Graham Higgins

unread,
Jun 11, 2009, 5:26:31 AM6/11/09
to pylons-discuss
On Jun 10, 6:53 pm, Mike Orr <sluggos...@gmail.com> wrote:
> This is the same error I reported yesterday, but I haven't seen any
> diagnosis yet.  I'll have to disable @beaker_cache in the meantime.

That's odd, I could have sworn that I posted something on this a
couple of weeks ago ... but it seems to have vanished into the aether.
P'raps I dreamed it.

I couldn't get either of the examples provided in Ben's blog post to
work in Pylons as is.

Using the cache decorator from pylons (tip) ...

I couldn't get @cache.region to work at all :-(

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)

I haven't had an opportunity to work through the Pylons source to
either i) clarify my understanding or ii) track down the source of the
problem (delete as appropriate).

HTH.

Graham.

Walter Cruz

unread,
Jun 11, 2009, 1:27:42 PM6/11/09
to pylons-...@googlegroups.com
On Thu, Jun 11, 2009 at 6:26 AM, Graham Higgins <gjhi...@googlemail.com> 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 ;)


--
[]'
- Walter
waltercruz.com

Ben Bangert

unread,
Jun 11, 2009, 5:59:54 PM6/11/09
to pylons-...@googlegroups.com
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

Graham Higgins

unread,
Jun 12, 2009, 9:06:04 AM6/12/09
to pylons-discuss

On Jun 11, 10:59 pm, Ben Bangert <b...@groovie.org> wrote:

> Here's the recommend method for using the Beaker cache object.

Fiat lux. Works flawlessly, just as you say. Thank you.

Cheers,

Graham.

Walter Cruz

unread,
Jun 12, 2009, 9:40:22 AM6/12/09
to pylons-...@googlegroups.com
and how to setup the render_mako caching ?
--
[]'
- Walter
waltercruz.com

Isaac Csandl

unread,
Jun 12, 2009, 11:31:09 AM6/12/09
to pylons-discuss


On Jun 11, 4:59 pm, Ben Bangert <b...@groovie.org> wrote:
> def load_cases(tag):
>      @app_globals.cache.region('short_term')


After 'short_term' you may also want to add another string to identify
the cache so you don't get overlapping values, eg:

@app_globals.cache.region('short_term', 'load_cases')


If the value of 'tag' in Ben's example would be unique enough amongst
all the values going into the short_term cache region to prevent
conflicts, then you could leave that additional string out. It depends
on how you're using the cache region.

HTH

--isaac

Isaac Csandl

unread,
Jun 12, 2009, 2:07:42 PM6/12/09
to pylons-discuss


On Jun 12, 10:31 am, Isaac Csandl <nerk...@gmail.com> wrote:

> If the value of 'tag' in Ben's example would be unique enough amongst
> all the values going into the short_term cache region to prevent
> conflicts, then you could leave that additional string out. It depends
> on how you're using the cache region.

Actually, that's not correct, sorry.

Suppose you have two cache regions that each use ext:memcached at the
same URL, but with different expiration times. If you're using the
same region more than once -- or multiple regions which use the same
storage -- from the same module, and the arguments to your decorated
functions have any potential to conflict, you should include a cache
name.

While developing, it's smart to run memcached with the -vv option so
you can see what the keys really are and spot conflicts.

For Ben's example, keys going to memcached could look like:
myapp.controllers.cases·tagname
or
myapp.lib.helpers·tagname -- which may be unique enough in some cases

... and with the cache name specified:
myapp.controllers.cases_load_cases·tagname
or
myapp.lib.helpers_load_cases·tagname

If you see weirdness with your caching (such as getting the wrong
value back from the cache sometimes), look into what's happening with
the keys.

--isaac

Kyle VanderBeek

unread,
Jun 14, 2009, 9:54:29 PM6/14/09
to pylons-discuss
I'm the maintainer for the Fedora RPM of Pylons, and I'm getting a
similar error in the nosetests run during my build. I too am using
Beaker 1.3.1. I wonder if there is something that needs to be updated
in the test_template_caching test, especially since it also throws a
warning for using the deprecated render_response(). I can't package
0.9.7 for all Fedora users until I get this resolved.

Relevant (long) output from my build and test run:

======================================================================
ERROR: test_default
(projectname.tests.functional.test_sample2.TestSample2Controller)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/builddir/build/BUILD/Pylons-0.9.7/tests/test_webapps/output/
ProjectName/projectname/tests/functional/test_sample2.py", line 14, in
test_default
response = self.app.get(url(controller='sample',
action='test_template_caching'))
File "/usr/lib/python2.6/site-packages/webtest/__init__.py", line
153, in get
expect_errors=expect_errors)
File "/usr/lib/python2.6/site-packages/webtest/__init__.py", line
310, in do_request
res = req.get_response(app, catch_exc_info=True)
File "/usr/lib/python2.6/site-packages/webob/__init__.py", line
1321, in get_response
application, catch_exc_info=True)
File "/usr/lib/python2.6/site-packages/webob/__init__.py", line
1293, in call_application
app_iter = application(self.environ, start_response)
File "/usr/lib/python2.6/site-packages/webtest/lint.py", line 170,
in lint_app
iterator = application(environ, start_response_wrapper)
File "/usr/lib/python2.6/site-packages/paste/cascade.py", line 130,
in __call__
return self.apps[-1](environ, start_response)
File "/usr/lib/python2.6/site-packages/paste/registry.py", line 350,
in __call__
app_iter = self.application(environ, start_response)
File "/usr/lib/python2.6/site-packages/paste/recursive.py", line 80,
in __call__
return self.application(environ, start_response)
File "/usr/lib/python2.6/site-packages/paste/errordocument.py", line
185, in __call__
app_iter = self.application(environ, change_response)
File "/usr/lib/python2.6/site-packages/weberror/evalexception.py",
line 235, in __call__
return self.respond(environ, start_response)
File "/usr/lib/python2.6/site-packages/weberror/evalexception.py",
line 418, in respond
return self.application(environ, start_response)
File "/usr/lib/python2.6/site-packages/beaker/middleware.py", line
70, in __call__
return self.app(environ, start_response)
File "/usr/lib/python2.6/site-packages/beaker/middleware.py", line
149, in __call__
return self.wrap_app(environ, session_start_response)
File "/usr/lib/python2.6/site-packages/routes/middleware.py", line
130, in __call__
response = self.app(environ, start_response)
File "/builddir/build/BUILD/Pylons-0.9.7/pylons/wsgiapp.py", line
125, in __call__
response = self.dispatch(controller, environ, start_response)
File "/builddir/build/BUILD/Pylons-0.9.7/pylons/wsgiapp.py", line
324, in dispatch
return controller(environ, start_response)
File "/builddir/build/BUILD/Pylons-0.9.7/tests/test_webapps/output/
ProjectName/projectname/lib/base.py", line 15, in __call__
return WSGIController.__call__(self, environ, start_response)
File "/builddir/build/BUILD/Pylons-0.9.7/pylons/controllers/
core.py", line 221, in __call__
response = self._dispatch_call()
File "/builddir/build/BUILD/Pylons-0.9.7/pylons/controllers/
core.py", line 172, in _dispatch_call
response = self._inspect_call(func)
File "/builddir/build/BUILD/Pylons-0.9.7/pylons/controllers/
core.py", line 107, in _inspect_call
result = self._perform_call(func, args)
File "/builddir/build/BUILD/Pylons-0.9.7/pylons/controllers/
core.py", line 60, in _perform_call
return func(**args)
File "/builddir/build/BUILD/Pylons-0.9.7/tests/test_webapps/output/
ProjectName/projectname/controllers/sample.py", line 48, in
test_template_caching
return render_mako('/test_mako.html', cache_expire='never')
File "/builddir/build/BUILD/Pylons-0.9.7/pylons/templating.py", line
274, in render_mako
cache_type=cache_type, cache_expire=cache_expire)
File "/builddir/build/BUILD/Pylons-0.9.7/pylons/templating.py", line
244, in cached_template
cache = pylons.cache.get_cache(namespace, type=cache_type)
File "/usr/lib/python2.6/site-packages/beaker/cache.py", line 187,
in get_cache
return self.caches.setdefault(name + str(kw), Cache(name, **kw))
File "/usr/lib/python2.6/site-packages/beaker/cache.py", line 104,
in __init__
self.namespace = cls(namespace, **nsargs)
File "/usr/lib/python2.6/site-packages/beaker/container.py", line
383, in __init__
raise MissingCacheParameter("data_dir or dbm_dir is required")
MissingCacheParameter: data_dir or dbm_dir is required
----------------------------------------------------------------------
Ran 19 tests in 0.254s
FAILED (errors=1)
-- created: -------------------
data/sessions/container_file/1
15
15971cbaca868514e81f2506503a844a.cache (125
bytes)
1c
1c80e8e87b7aeb150ec72cc61f136b2e.cache (126
bytes)
6/6b
6b6c6c4790d5ca2e7c53c46a985aac3d.cache (129
bytes)
container_file_lock/4
43
431757b2d304c57a11bc3ec8dc1b246d69b62b9a.lock
(0 bytes)
c/c0
c0c63f170748738d2247483a771754cc25eb9839.lock
(0 bytes)
d
d6
d6b67a2bebf25c43e27ab8a4b0d3b2180d40dc0f.lock
(0 bytes)
-- updated: -------------------
projectname/config/middleware.pyc (2437 bytes)
tests/functional/test_sample2.pyc (1494 bytes)
----------------------------------------
--------------------- >> end captured stdout << ----------------------
----------------------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages