File: Cache.py

package info (click to toggle)
tilecache 2.11%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 532 kB
  • ctags: 423
  • sloc: python: 3,086; makefile: 90
file content (48 lines) | stat: -rw-r--r-- 1,586 bytes parent folder | download | duplicates (3)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# BSD Licensed, Copyright (c) 2006-2010 TileCache Contributors
import os, sys, time
from warnings import warn

class Cache (object):
    def __init__ (self, timeout = 30.0, stale_interval = 300.0, readonly = False, expire = False, sendfile = False, **kwargs):
        self.stale    = float(stale_interval)
        self.timeout = float(timeout)
        self.readonly = readonly
        self.expire = expire
        self.sendfile = sendfile and sendfile.lower() in ["yes", "y", "t", "true"]
        if expire != False:
            self.expire = long(expire)
                
    def lock (self, tile, blocking = True):
        start_time = time.time()
        result = self.attemptLock(tile)
        if result:
            return True
        elif not blocking:
            return False
        while result is not True:
            if time.time() - start_time > self.timeout:
                raise Exception("You appear to have a stuck lock. You may wish to remove the lock named:\n%s" % self.getLockName(tile)) 
            time.sleep(0.25)
            result = self.attemptLock(tile)
        return True

    def getLockName (self, tile):
        return self.getKey(tile) + ".lck"

    def getKey (self, tile):
        raise NotImplementedError()

    def attemptLock (self, tile):
        raise NotImplementedError()

    def unlock (self, tile):
        raise NotImplementedError()

    def get (self, tile):
        raise NotImplementedError()

    def set (self, tile, data):
        raise NotImplementedError()
    
    def delete(self, tile):
        raise NotImplementedError()