7
7
8
8
CACHE_COLL = 'cache'
9
9
CACHE_DB = 'meta_db'
10
- CACHE_SETTINGS = 'cache_settings'
10
+ CACHE_SETTINGS = 'settings'
11
+ CACHE_SETTINGS_KEY = 'cache'
11
12
"""
12
13
Sample cache_settings collection entry:
13
- meta_db.cache_settings.insertOne({"enabled": true, "cache_expiry": 600})
14
- meta_db.cache_settings.find(): { "_id" : ObjectId("5cd5388b9fddfbe6e968f11b"), "enabled" : false, "cache_expiry" : 600 }
14
+ meta_db.cache_settings.insertOne({"type": "cache", " enabled": true, "cache_expiry": 600})
15
+ meta_db.cache_settings.find(): { "_id" : ObjectId("5cd5388b9fddfbe6e968f11b"), "type": "cache", " enabled" : false, "cache_expiry" : 600 }
15
16
"""
16
17
DEFAULT_CACHE_EXPIRY = 3600
17
18
@@ -31,7 +32,7 @@ def __init__(self, client, cache_expiry=DEFAULT_CACHE_EXPIRY, cache_db=CACHE_DB,
31
32
32
33
def _get_cache_settings (self ):
33
34
try :
34
- return self ._cachedb [CACHE_SETTINGS ].find_one ()
35
+ return self ._cachedb [CACHE_SETTINGS ].find_one ({ 'type' : CACHE_SETTINGS_KEY } )
35
36
except OperationFailure as op :
36
37
logging .debug ("Cannot access %s in db: %s. Error: %s" % (CACHE_SETTINGS , CACHE_DB , op ))
37
38
return None
@@ -48,11 +49,12 @@ def set_caching_state(self, enabled):
48
49
if CACHE_SETTINGS not in self ._cachedb .list_collection_names ():
49
50
logging .info ("Creating %s collection for cache settings" % CACHE_SETTINGS )
50
51
self ._cachedb [CACHE_SETTINGS ].insert_one ({
52
+ 'type' : CACHE_SETTINGS_KEY ,
51
53
'enabled' : enabled ,
52
54
'cache_expiry' : DEFAULT_CACHE_EXPIRY
53
55
})
54
56
else :
55
- self ._cachedb [CACHE_SETTINGS ].update_one ({}, {'$set' : {'enabled' : enabled }})
57
+ self ._cachedb [CACHE_SETTINGS ].update_one ({'type' : CACHE_SETTINGS_KEY }, {'$set' : {'enabled' : enabled }})
56
58
logging .info ("Caching set to: %s" % enabled )
57
59
58
60
def _is_not_expired (self , cached_data , newer_than_secs ):
0 commit comments