Entropy/DistributionUGCInterface:

- make cache expiration time configurable per cache item


git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@2727 cd1c1023-2f26-0410-ae45-c471fc1f0318
This commit is contained in:
lxnay
2008-12-06 15:39:08 +00:00
parent 4b9c8956a8
commit 7712fcb660

View File

@@ -17552,12 +17552,11 @@ class DistributionUGCInterface(RemoteDbSkelInterface):
pass
self.cached_results = {
#'get_ugc_allvotes': (self.get_ugc_allvotes, [], {}),
'get_ugc_alldownloads': (self.get_ugc_alldownloads, [], {}),
#'get_users_scored_count': (self.get_users_scored_count, [], {}),
'get_total_downloads_count': (self.get_total_downloads_count, [], {}),
#'get_ugc_allvotes': (self.get_ugc_allvotes, [], {}, 86400),
'get_ugc_alldownloads': (self.get_ugc_alldownloads, [], {}, 86400),
#'get_users_scored_count': (self.get_users_scored_count, [], {}, 86400),
'get_total_downloads_count': (self.get_total_downloads_count, [], {}, 7200),
}
self.cache_expire_timer = 86400 # 1 day
def get_current_time(self):
return int(time.time())
@@ -17566,7 +17565,7 @@ class DistributionUGCInterface(RemoteDbSkelInterface):
for cache_item in self.cached_results:
fdata = self.cached_results.get(cache_item)
if fdata == None: return
func, args, kwargs = fdata
func, args, kwargs, exp_time = fdata
key = self.get_cache_item_key(cache_item)
r = func(*args,**kwargs)
self.dumpTools.dumpobj(key, r)
@@ -17581,11 +17580,15 @@ class DistributionUGCInterface(RemoteDbSkelInterface):
# expired get_ugc_alldownloads 0 86400 1228577077
def get_cached_result(self, cache_item):
if not self.cached_results.get(cache_item): return None
fdata = self.cached_results.get(cache_item)
if fdata == None: return None
func, args, kwargs, exp_time = fdata
key = self.get_cache_item_key(cache_item)
cur_time = self.get_current_time()
cache_time = self.dumpTools.getobjmtime(key)
if (cache_time + self.cache_expire_timer) < cur_time:
exp_timer = self.cached_results
if (cache_time + exp_timer) < cur_time:
# expired
return None
return self.dumpTools.loadobj(key)