/usr/lib/python3/dist-packages/tunigo/cache.py is in python3-tunigo 1.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | from __future__ import unicode_literals
import time
class Cache(object):
def __init__(self, cache_time):
self._cache = {}
self._cache_time = cache_time
def __repr__(self):
return 'Cache(cache_time={})'.format(self._cache_time)
def _cache_valid(self, key):
return (key in self._cache and
self._cache[key]['access_time'] >
time.time() - self._cache_time)
def get(self, key):
if self._cache_valid(key):
return self._cache[key]['obj']
else:
return None
def insert(self, key, obj):
if self._cache_time:
self._cache[key] = {
'access_time': time.time(),
'obj': obj
}
|