summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2015-09-20 17:47:07 -0300
committerVictor Shyba <victor.shyba@gmail.com>2015-09-24 19:40:51 -0300
commit0e954f3328b7b8c31c88e0bee796230e87bca829 (patch)
treefb70bebfe0d8d363d4516ce6d4b61497d5be3395 /server
parentfc5f4ae965ca48946af9f6982b2719562168131c (diff)
[feat] adds cache expiration
Now each backend object will be retrieved from cache for sync.py and values will live for 3600 by default. That is changed via parameter if needed.
Diffstat (limited to 'server')
-rw-r--r--server/src/leap/soledad/server/caching.py4
-rw-r--r--server/src/leap/soledad/server/sync.py5
2 files changed, 6 insertions, 3 deletions
diff --git a/server/src/leap/soledad/server/caching.py b/server/src/leap/soledad/server/caching.py
index cd5d8dd4..9a049a39 100644
--- a/server/src/leap/soledad/server/caching.py
+++ b/server/src/leap/soledad/server/caching.py
@@ -28,5 +28,5 @@ def setup_caching():
_cache_manager = setup_caching()
-def get_cache_for(key):
- return _cache_manager.get_cache(key)
+def get_cache_for(key, expire=3600):
+ return _cache_manager.get_cache(key, expire=expire)
diff --git a/server/src/leap/soledad/server/sync.py b/server/src/leap/soledad/server/sync.py
index 262b6769..e4fd1260 100644
--- a/server/src/leap/soledad/server/sync.py
+++ b/server/src/leap/soledad/server/sync.py
@@ -185,12 +185,15 @@ class SyncResource(http_app.SyncResource):
:type ensure: bool
"""
# create or open the database
+ cache = get_cache_for('db-' + sync_id + self.dbname)
if ensure:
db, self.replica_uid = self.state.ensure_database(self.dbname)
+ elif cache and 'instance' in cache:
+ db = cache['instance']
else:
db = self.state.open_database(self.dbname)
- cache = get_cache_for('db-' + sync_id + db.replica_uid)
db._cache = cache
+ cache['instance'] = db
# validate the information the client has about server replica
db.validate_gen_and_trans_id(
last_known_generation, last_known_trans_id)