Ticket #9761: filebased.patch

File filebased.patch, 728 bytes (added by fero, 16 years ago)

filebased cache patch example for extending the cachebackends API

  • filebased.py

    old new  
    3737        self.set(key, value, timeout)
    3838        return True
    3939
     40    def when_cached(self, key, default=0):
     41        fname = self._key_to_file(key)
     42        rv = default
     43        try:
     44            rv = os.stat(fname)[8]
     45        except (IOError, OSError, EOFError, pickle.PickleError):
     46            pass
     47        return rv
     48               
     49    def get_if_newer(self, key, timestamp, default=None):
     50        rv = default
     51        if self.when_cached(key) > timestamp:
     52            rv = self.get(key)
     53        return rv
     54
    4055    def get(self, key, default=None):
    4156        fname = self._key_to_file(key)
    4257        try:
Back to Top