1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from buildbot.util import lru
17 from buildbot import config
18 from twisted.application import service
19
20 -class CacheManager(config.ReconfigurableServiceMixin, service.Service):
21 """
22 A manager for a collection of caches, each for different types of objects
23 and with potentially-overlapping key spaces.
24
25 There is generally only one instance of this class, available at
26 C{master.caches}.
27 """
28
29
30
31
32 DEFAULT_CACHE_SIZE = 1
33
35 self.setName('caches')
36 self.config = {}
37 self._caches = {}
38
40 """
41 Get an L{AsyncLRUCache} object with the given name. If such an object
42 does not exist, it will be created. Since the cache is permanent, this
43 method can be called only once, e.g., in C{startService}, and it value
44 stored indefinitely.
45
46 @param cache_name: name of the cache (usually the name of the type of
47 object it stores)
48 @param miss_fn: miss function for the cache; see L{AsyncLRUCache}
49 constructor.
50 @returns: L{AsyncLRUCache} instance
51 """
52 try:
53 return self._caches[cache_name]
54 except KeyError:
55 max_size = self.config.get(cache_name, self.DEFAULT_CACHE_SIZE)
56 assert max_size >= 1
57 c = self._caches[cache_name] = lru.AsyncLRUCache(miss_fn, max_size)
58 return c
59
68
74