Can't have a global cache

213 views Asked by At

I have defined this cache file with dogpile [1]. But my problem is that when I invoke the key in different classes, it can't find the value. Eg, If I am running cache.Cache.save("mykey", 123) in the main.py, and during the execution I am retrieving the value in another module submodule.py with cache.Cache.get("mykey"), I can't retrieve the value. I get NoValue. It seems that I am not creating a unique and global cache for all my program.

All the set and get to the cache are made by this module mycache.py. Why this is happening?

[1] mycache.py

from dogpile.cache import make_region

region = make_region().configure('dogpile.cache.memory')
class Cache:

  @staticmethod
  def save(key, value):
    region.set(key, value)

  @staticmethod
  def get(key):
    return region.get(key)
1

There are 1 answers

0
xeon123 On

Well, I have solved this problem by saving the cache into a file.

region = make_region().configure('dogpile.cache.dbm',
                             expiration_time = 3600,
                             arguments = {
                                 "filename":"./cache_execution.dbm"
                             })