Subversion Repositories SmartDukaan

Rev

Rev 3098 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3098 Rev 3148
Line 19... Line 19...
19
    def __call__(self, func):
19
    def __call__(self, func):
20
        def wrapped_function(*args):
20
        def wrapped_function(*args):
21
            try:
21
            try:
22
                now = time.time()
22
                now = time.time()
23
                value, last_update = self.cache[args]
23
                value, last_update = self.cache[args]
24
                print "HIT"
-
 
25
                if now - last_update > self.ttl:
24
                if now - last_update > self.ttl:
26
                    print "EXPIRED"
25
                    print "EXPIRED"
27
                    raise AttributeError
26
                    raise AttributeError
-
 
27
                print "HIT"
28
            except (KeyError, AttributeError):
28
            except KeyError:
29
                print "MISS"
29
                print "MISS"
30
                value = func(*args)
30
                value = func(*args)
31
                self.cache[args] = value, now
31
                self.cache[args] = value, now
-
 
32
            except AttributeError:
-
 
33
                value = func(*args)
-
 
34
                self.cache[args] = value, now
32
            except TypeError:
35
            except TypeError:
33
                print "MISS"
36
                print "MISS"
34
                return func(*args)
37
                return func(*args)
35
            return value
38
            return value
36
        return wrapped_function
39
        return wrapped_function