File tree 1 file changed +16
-7
lines changed
1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change 1
1
# Copyright (C) 2008-2011 Dejan Muhamedagic <[email protected] >
2
+ # Copyright (C) 2018 Kristoffer Gronlund <[email protected] >
2
3
# See COPYING for license information.
3
4
#
4
5
# Cache stuff. A naive implementation.
6
+ # Used by ra.py to cache named lists of things.
5
7
6
8
import time
7
9
8
10
9
- _max_cache_age = 600 # seconds
11
+ _max_cache_age = 600.0 # seconds
10
12
_stamp = time .time ()
11
13
_lists = {}
12
14
13
15
14
16
def _clear ():
17
+ "Clear the cache."
15
18
global _stamp
16
19
global _lists
17
20
_stamp = time .time ()
18
21
_lists = {}
19
22
20
23
21
24
def is_cached (name ):
22
- if time .time () - _stamp > _max_cache_age :
23
- _clear ()
24
- return name in _lists
25
+ "True if the argument exists in the cache."
26
+ return retrieve (name ) is not None
25
27
26
28
27
29
def store (name , lst ):
30
+ """
31
+ Stores the given list for the given name.
32
+ Returns the given list.
33
+ """
28
34
_lists [name ] = lst
29
35
return lst
30
36
31
37
32
38
def retrieve (name ):
33
- if is_cached (name ):
34
- return _lists [name ]
35
- return None
39
+ """
40
+ Returns the cached list for name, or None.
41
+ """
42
+ if time .time () - _stamp > _max_cache_age :
43
+ _clear ()
44
+ return _lists .get (name )
36
45
37
46
38
47
# vim:ts=4:sw=4:et:
You can’t perform that action at this time.
0 commit comments