OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from appengine_wrappers import CACHE_TIMEOUT | 5 from appengine_wrappers import CACHE_TIMEOUT |
6 from future import Future | 6 from future import Future |
7 | 7 |
8 BRANCH_UTILITY = 'BranchUtility' | |
9 FILE_SYSTEM_CACHE = 'CompiledFileSystem' | |
10 FILE_SYSTEM_CACHE_LISTING = 'CompiledFileSystemListing' | |
11 FILE_SYSTEM_READ = 'Read' | |
12 FILE_SYSTEM_STAT = 'Stat' | |
13 GITHUB_STAT = 'GithubStat' | |
14 KNOWN_ISSUES = 'KnownIssues' | |
15 REFERENCE_RESOLVER = 'ReferenceResolver' | |
16 | |
17 class _SingleGetFuture(object): | 8 class _SingleGetFuture(object): |
18 def __init__(self, multi_get, key): | 9 def __init__(self, multi_get, key): |
19 self._future = multi_get | 10 self._future = multi_get |
20 self._key = key | 11 self._key = key |
21 | 12 |
22 def Get(self): | 13 def Get(self): |
23 return self._future.Get()[self._key] | 14 return self._future.Get().get(self._key) |
24 | 15 |
25 class ObjectStore(object): | 16 class ObjectStore(object): |
26 """A class for caching picklable objects. | 17 """A class for caching picklable objects. |
27 """ | 18 """ |
28 def Set(self, key, value, namespace, time=CACHE_TIMEOUT): | 19 def Set(self, key, value, time=CACHE_TIMEOUT): |
29 """Sets key -> value in the object store, with the specified timeout. | 20 """Sets key -> value in the object store, with the specified timeout. |
30 """ | 21 """ |
31 self.SetMulti({ key: value }, namespace, time=time) | 22 self.SetMulti({ key: value }, time=time) |
32 | 23 |
33 def SetMulti(self, mapping, namespace, time=CACHE_TIMEOUT): | 24 def SetMulti(self, mapping, time=CACHE_TIMEOUT): |
34 """Sets the mapping of keys to values in the object store with the specified | 25 """Sets the mapping of keys to values in the object store with the specified |
35 timeout. | 26 timeout. |
36 """ | 27 """ |
37 raise NotImplementedError() | 28 raise NotImplementedError() |
38 | 29 |
39 def Get(self, key, namespace, time=CACHE_TIMEOUT): | 30 def Get(self, key, time=CACHE_TIMEOUT): |
40 """Gets a |Future| with the value of |key| in the object store, or None | 31 """Gets a |Future| with the value of |key| in the object store, or None |
41 if |key| is not in the object store. | 32 if |key| is not in the object store. |
42 """ | 33 """ |
43 return Future(delegate=_SingleGetFuture( | 34 return Future(delegate=_SingleGetFuture(self.GetMulti([key], time=time), |
44 self.GetMulti([key], namespace, time=time), | 35 key)) |
45 key)) | |
46 | 36 |
47 def GetMulti(self, keys, namespace, time=CACHE_TIMEOUT): | 37 def GetMulti(self, keys, time=CACHE_TIMEOUT): |
48 """Gets a |Future| with values mapped to |keys| from the object store, with | 38 """Gets a |Future| with values mapped to |keys| from the object store, with |
49 any keys not in the object store mapped to None. | 39 any keys not in the object store mapped to None. |
50 """ | 40 """ |
51 raise NotImplementedError() | 41 raise NotImplementedError() |
52 | 42 |
53 def Delete(self, key, namespace): | 43 def Delete(self, key): |
54 """Deletes a key from the object store. | 44 """Deletes a key from the object store. |
55 """ | 45 """ |
56 raise NotImplementedError() | 46 raise NotImplementedError() |
OLD | NEW |