|
Package memtools ::
Module protocols
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 """
36 This file defines the required protocols for most memory tools used
37 in this package.
38
39 """
40
41
42 from functools import wraps
43 from memtools.pattern import Memorized, memorize
44
45
47 """
48 Memory objects are key-value gateways to a database or any other kind
49 of memory storage. They behave the same way dictionaries do, which
50 makes it easier to mock them.
51
52 Required methods are __getitem__, __setitem__ and __delitem__. get(),
53 set() are mapped to __getitem__ and __setitem__.
54
55 A convenience method __call__ is defined to use objects of this class
56 as decorators. Doing so will apply the memorize pattern to the
57 function. You can find more information in the corresponding docstring
58 in __call__.
59
60 """
61
63 raise NotImplementedError
64
66 raise NotImplementedError
67
69 raise NotImplementedError
70
72 """
73 This is a convenience function that provides the Memory Pattern as
74 a decorator and wraps it in a way transparent to the end user
75 (i.e.: they will not know whether the function has been decorated
76 or not). This is acomplished by using the "wrap" decorator in
77 functools.
78
79 """
80 memo = Memorized(f, self)
81 wraps(f)(memo)
82 return memo
83
86
87 - def set(self, key, value):
89
90
92 """
93 A MemoryPool object provides an extended way of using Memory gateways.
94 It holds more than one connection open, so it should be theoretically
95 faster than ad-hoc connections. However, it does not necessarily imply
96 that the objects in the pool are connected to different servers.
97
98 It *must* behave like a Memory gateway too, masking the
99 lock/hold/return operations inside the MemoryPool, providing a complete
100 replacement for normal Memory objects.
101 """
102
104 raise NotImplementedError
105
106 - def grow(self, number=1):
107 raise NotImplementedError
108
110 raise NotImplementedError
111