Skip to content

Mongo cache syntax isn't working.  #30

Open
@chengguangnan

Description

@chengguangnan

I need to use this code:

# enable sunlight cache
setattr(sunlight.config, 'MONGO_HOST', C.Mgr.MONGO_HOST)
sunlight.cache.response_cache = sunlight.cache.MongoBackend()

The code in the document will throw exception:

import logging
from sunlight import response_cache
response_cache.enable('mongo')
response_cache.logger.setLevel(logging.DEBUG)

Exception:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/home/chengguangnan/anaconda3/lib/python3.5/site-packages/sunlight/cache.py in set_backend(self, backend_name)
    107         try:
--> 108             self.backend = backends[backend_name]()
    109             self.logger.info('Changed cache backend to %r.' % self.backend)

KeyError: 'mongo'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-24-2766d9958dbe> in <module>()
      1 import logging
      2 from sunlight import response_cache
----> 3 response_cache.enable('mongo')
      4 response_cache.logger.setLevel(logging.DEBUG)

/home/chengguangnan/anaconda3/lib/python3.5/site-packages/sunlight/cache.py in set_backend(self, backend_name)
    109             self.logger.info('Changed cache backend to %r.' % self.backend)
    110         except KeyError:
--> 111             raise ValueError('No backend named %r is defined.' % backend_name)
    112 
    113     enable = set_backend

ValueError: No backend named 'mongo' is defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions