Show More
@@ -0,0 +1,65 b'' | |||||
|
1 | # -*- coding: utf-8 -*- | |||
|
2 | ||||
|
3 | # RhodeCode VCSServer provides access to different vcs backends via network. | |||
|
4 | # Copyright (C) 2014-2018 RhodeCode GmbH | |||
|
5 | # | |||
|
6 | # This program is free software; you can redistribute it and/or modify | |||
|
7 | # it under the terms of the GNU General Public License as published by | |||
|
8 | # the Free Software Foundation; either version 3 of the License, or | |||
|
9 | # (at your option) any later version. | |||
|
10 | # | |||
|
11 | # This program is distributed in the hope that it will be useful, | |||
|
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
14 | # GNU General Public License for more details. | |||
|
15 | # | |||
|
16 | # You should have received a copy of the GNU General Public License | |||
|
17 | # along with this program; if not, write to the Free Software Foundation, | |||
|
18 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |||
|
19 | ||||
|
20 | ||||
|
21 | import logging | |||
|
22 | ||||
|
23 | from repoze.lru import LRUCache | |||
|
24 | ||||
|
25 | from vcsserver.utils import safe_str | |||
|
26 | ||||
|
27 | log = logging.getLogger(__name__) | |||
|
28 | ||||
|
29 | ||||
|
30 | class LRUDict(LRUCache): | |||
|
31 | """ | |||
|
32 | Wrapper to provide partial dict access | |||
|
33 | """ | |||
|
34 | ||||
|
35 | def __setitem__(self, key, value): | |||
|
36 | return self.put(key, value) | |||
|
37 | ||||
|
38 | def __getitem__(self, key): | |||
|
39 | return self.get(key) | |||
|
40 | ||||
|
41 | def __contains__(self, key): | |||
|
42 | return bool(self.get(key)) | |||
|
43 | ||||
|
44 | def __delitem__(self, key): | |||
|
45 | del self.data[key] | |||
|
46 | ||||
|
47 | def keys(self): | |||
|
48 | return self.data.keys() | |||
|
49 | ||||
|
50 | ||||
|
51 | class LRUDictDebug(LRUDict): | |||
|
52 | """ | |||
|
53 | Wrapper to provide some debug options | |||
|
54 | """ | |||
|
55 | def _report_keys(self): | |||
|
56 | elems_cnt = '%s/%s' % (len(self.keys()), self.size) | |||
|
57 | # trick for pformat print it more nicely | |||
|
58 | fmt = '\n' | |||
|
59 | for cnt, elem in enumerate(self.keys()): | |||
|
60 | fmt += '%s - %s\n' % (cnt+1, safe_str(elem)) | |||
|
61 | log.debug('current LRU keys (%s):%s' % (elems_cnt, fmt)) | |||
|
62 | ||||
|
63 | def __getitem__(self, key): | |||
|
64 | self._report_keys() | |||
|
65 | return self.get(key) |
@@ -287,17 +287,6 b' self: super: {' | |||||
287 | license = [ pkgs.lib.licenses.bsdOriginal ]; |
|
287 | license = [ pkgs.lib.licenses.bsdOriginal ]; | |
288 | }; |
|
288 | }; | |
289 | }; |
|
289 | }; | |
290 | "lru-dict" = super.buildPythonPackage { |
|
|||
291 | name = "lru-dict-1.1.6"; |
|
|||
292 | doCheck = false; |
|
|||
293 | src = fetchurl { |
|
|||
294 | url = "https://files.pythonhosted.org/packages/00/a5/32ed6e10246cd341ca8cc205acea5d208e4053f48a4dced2b1b31d45ba3f/lru-dict-1.1.6.tar.gz"; |
|
|||
295 | sha256 = "1k2lhd4dpl6xa6iialbwx4l6bkdzxmzhygms39pvf19x1rk5fm1n"; |
|
|||
296 | }; |
|
|||
297 | meta = { |
|
|||
298 | license = [ pkgs.lib.licenses.mit ]; |
|
|||
299 | }; |
|
|||
300 | }; |
|
|||
301 | "mako" = super.buildPythonPackage { |
|
290 | "mako" = super.buildPythonPackage { | |
302 | name = "mako-1.0.7"; |
|
291 | name = "mako-1.0.7"; | |
303 | doCheck = false; |
|
292 | doCheck = false; | |
@@ -691,7 +680,6 b' self: super: {' | |||||
691 | self."dulwich" |
|
680 | self."dulwich" | |
692 | self."hgsubversion" |
|
681 | self."hgsubversion" | |
693 | self."hg-evolve" |
|
682 | self."hg-evolve" | |
694 | self."lru-dict" |
|
|||
695 | self."mako" |
|
683 | self."mako" | |
696 | self."markupsafe" |
|
684 | self."markupsafe" | |
697 | self."mercurial" |
|
685 | self."mercurial" |
@@ -8,7 +8,6 b' decorator==4.1.2' | |||||
8 | dulwich==0.13.0 |
|
8 | dulwich==0.13.0 | |
9 | hgsubversion==1.9.2 |
|
9 | hgsubversion==1.9.2 | |
10 | hg-evolve==8.0.1 |
|
10 | hg-evolve==8.0.1 | |
11 | lru-dict==1.1.6 |
|
|||
12 | mako==1.0.7 |
|
11 | mako==1.0.7 | |
13 | markupsafe==1.0.0 |
|
12 | markupsafe==1.0.0 | |
14 | mercurial==4.6.2 |
|
13 | mercurial==4.6.2 |
@@ -18,7 +18,7 b'' | |||||
18 | import logging |
|
18 | import logging | |
19 |
|
19 | |||
20 | from dogpile.cache.backends import memory as memory_backend |
|
20 | from dogpile.cache.backends import memory as memory_backend | |
21 | from lru import LRU as LRUDict |
|
21 | from vcsserver.lib.memory_lru_dict import LRUDict, LRUDictDebug | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | _default_max_size = 1024 |
|
24 | _default_max_size = 1024 | |
@@ -31,21 +31,21 b' class LRUMemoryBackend(memory_backend.Me' | |||||
31 |
|
31 | |||
32 | def __init__(self, arguments): |
|
32 | def __init__(self, arguments): | |
33 | max_size = arguments.pop('max_size', _default_max_size) |
|
33 | max_size = arguments.pop('max_size', _default_max_size) | |
34 | callback = None |
|
|||
35 | if arguments.pop('log_max_size_reached', None): |
|
|||
36 | def evicted(key, value): |
|
|||
37 | log.debug( |
|
|||
38 | 'LRU: evicting key `%s` due to max size %s reach', key, max_size) |
|
|||
39 | callback = evicted |
|
|||
40 |
|
34 | |||
41 | arguments['cache_dict'] = LRUDict(max_size, callback=callback) |
|
35 | LRUDictClass = LRUDict | |
|
36 | if arguments.pop('log_key_count', None): | |||
|
37 | LRUDictClass = LRUDictDebug | |||
|
38 | ||||
|
39 | arguments['cache_dict'] = LRUDictClass(max_size) | |||
42 | super(LRUMemoryBackend, self).__init__(arguments) |
|
40 | super(LRUMemoryBackend, self).__init__(arguments) | |
43 |
|
41 | |||
44 | def delete(self, key): |
|
42 | def delete(self, key): | |
45 | if self._cache.has_key(key): |
|
43 | try: | |
46 | del self._cache[key] |
|
44 | del self._cache[key] | |
|
45 | except KeyError: | |||
|
46 | # we don't care if key isn't there at deletion | |||
|
47 | pass | |||
47 |
|
48 | |||
48 | def delete_multi(self, keys): |
|
49 | def delete_multi(self, keys): | |
49 | for key in keys: |
|
50 | for key in keys: | |
50 |
|
|
51 | self.delete(key) | |
51 | del self._cache[key] |
|
General Comments 0
You need to be logged in to leave comments.
Login now