Add __cache_file method
This commit is contained in:
+9
-9
@@ -37,28 +37,28 @@ class LazyDB(Singleton):
|
|||||||
def is_initialized(self):
|
def is_initialized(self):
|
||||||
return self.initialized
|
return self.initialized
|
||||||
|
|
||||||
|
def __cache_file(self):
|
||||||
|
return "/var/cache/pisi/%s.cache" % self.__class__.__name__.lower()
|
||||||
|
|
||||||
def cache_save(self):
|
def cache_save(self):
|
||||||
if os.access("/var/cache/pisi", os.W_OK) and self.cacheable:
|
if os.access("/var/cache/pisi", os.W_OK) and self.cacheable:
|
||||||
cPickle.dump(self._instance().__dict__,
|
cPickle.dump(self._instance().__dict__,
|
||||||
file('/var/cache/pisi/%s.cache' % self.__class__.__name__.lower(), 'wb'), 1)
|
file(self.__cache_file(), 'wb'), 1)
|
||||||
|
|
||||||
def cache_load(self):
|
def cache_load(self):
|
||||||
cache_file = "/var/cache/pisi/%s.cache" % self.__class__.__name__.lower()
|
if os.path.exists(self.__cache_file()):
|
||||||
if os.path.exists(cache_file):
|
|
||||||
try:
|
try:
|
||||||
self._instance().__dict__ = cPickle.load(file(cache_file, 'rb'))
|
self._instance().__dict__ = cPickle.load(file(self.__cache_file(), 'rb'))
|
||||||
return True
|
return True
|
||||||
except cPickle.UnpicklingError:
|
except cPickle.UnpicklingError:
|
||||||
# Delete corrupted cache
|
|
||||||
if os.access("/var/cache/pisi", os.W_OK):
|
if os.access("/var/cache/pisi", os.W_OK):
|
||||||
os.unlink(cache_file)
|
os.unlink(self.__cache_file())
|
||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def cache_flush(self):
|
def cache_flush(self):
|
||||||
cache_file = "/var/cache/pisi/%s.cache" % self.__class__.__name__.lower()
|
if os.path.exists(self.__cache_file()):
|
||||||
if os.path.exists(cache_file):
|
os.unlink(self.__cache_file())
|
||||||
os.unlink(cache_file)
|
|
||||||
|
|
||||||
def invalidate(self):
|
def invalidate(self):
|
||||||
self._delete()
|
self._delete()
|
||||||
|
|||||||
Reference in New Issue
Block a user