bbangert / beaker

WSGI middleware for sessions and caching
https://beaker.readthedocs.org/
Other
517 stars 147 forks source link

How can I configure NamespaceManager to realize distributed cache? #194

Open vba34520 opened 3 years ago

vba34520 commented 3 years ago

Such as MongoDB

from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options

cache_opts = {
    'cache.type': 'ext:mongodb',
    'cache.url': 'mongodb://localhost:27017/cache',
    'cache.expire': 600
}

cache = CacheManager(**parse_cache_config_options(cache_opts))

@cache.cache('fib')
def fib(n):
    if n < 2:
        return n
    return fib(n - 1) + fib(n - 2)

if __name__ == '__main__':
    result = [fib(i) for i in range(35)]
    print(result)

result

image.png

If the _id can be configure, it's easy to realize distributed cache.

Looking forward to your reply, thank you for your great work!