Pyramid with memcached: how to make it work? Error - MissingCacheParameter: url is required

梦想与她 提交于 2019-12-06 03:02:45

So, using the TurboGears documentation as a guide, what settings do you have for the url?

[app:main]
beaker.cache.type = ext:memcached
beaker.cache.url = 127.0.0.1:11211
# you can also store sessions in memcached, should you wish
# beaker.session.type = ext:memcached
# beaker.session.url = 127.0.0.1:11211

It looks to me as if memcached requires a url to initialize correctly:

def __init__(self, namespace, url=None, data_dir=None, lock_dir=None, **params):
    NamespaceManager.__init__(self, namespace)

    if not url:
        raise MissingCacheParameter("url is required") 

I am not really sure why the code allows url to be optional (defaulting to None) and then requires it. I think it would have been simpler just to require the url as an argument.


Later: in response to your next question:

when I used cache.url I've got next error: AttributeError: 'MemcachedNamespaceManager' object has no attribute 'lock_dir'

I'd say that the way I read the code below, you have to provide either lock_dir or data_dir to initialize self.lock_dir:

    if lock_dir:
        self.lock_dir = lock_dir
    elif data_dir:
        self.lock_dir = data_dir + "/container_mcd_lock"
    if self.lock_dir:
        verify_directory(self.lock_dir)

You can replicate that exact error using this test code:

class Foo(object):
    def __init__(self, lock_dir=None, data_dir=None):
        if lock_dir:
            self.lock_dir = lock_dir
        elif data_dir:
            self.lock_dir = data_dir + "/container_mcd_lock"
        if self.lock_dir:
            verify_directory(self.lock_dir)

f = Foo()

It turns out like this:

>>> f = Foo()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 7, in __init__
AttributeError: 'Foo' object has no attribute 'lock_dir'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!