|
1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>eric6.E5Utilities.E5Cache</title> |
|
4 <meta charset="UTF-8"> |
|
5 <style> |
|
6 body { |
|
7 background: #EDECE6; |
|
8 margin: 0em 1em 10em 1em; |
|
9 color: black; |
|
10 } |
|
11 |
|
12 h1 { color: white; background: #85774A; } |
|
13 h2 { color: white; background: #85774A; } |
|
14 h3 { color: white; background: #9D936E; } |
|
15 h4 { color: white; background: #9D936E; } |
|
16 |
|
17 a { color: #BA6D36; } |
|
18 |
|
19 </style> |
|
20 </head> |
|
21 <body><a NAME="top" ID="top"></a> |
|
22 <h1>eric6.E5Utilities.E5Cache</h1> |
|
23 <p> |
|
24 Module implementing classes used for caching objects. |
|
25 </p> |
|
26 <h3>Global Attributes</h3> |
|
27 <table> |
|
28 <tr><td>None</td></tr> |
|
29 </table> |
|
30 <h3>Classes</h3> |
|
31 <table> |
|
32 <tr> |
|
33 <td><a href="#E5Cache">E5Cache</a></td> |
|
34 <td>Class implementing a LRU cache of a specific size.</td> |
|
35 </tr> |
|
36 </table> |
|
37 <h3>Functions</h3> |
|
38 <table> |
|
39 <tr><td>None</td></tr> |
|
40 </table> |
|
41 <hr /><hr /> |
|
42 <a NAME="E5Cache" ID="E5Cache"></a> |
|
43 <h2>E5Cache</h2> |
|
44 <p> |
|
45 Class implementing a LRU cache of a specific size. |
|
46 </p><p> |
|
47 If the maximum number of entries is exceeded, the least recently used item |
|
48 is removed from the cache. A cache hit moves the entry to the front of the |
|
49 cache. |
|
50 </p> |
|
51 <h3>Derived from</h3> |
|
52 object |
|
53 <h3>Class Attributes</h3> |
|
54 <table> |
|
55 <tr><td>None</td></tr> |
|
56 </table> |
|
57 <h3>Class Methods</h3> |
|
58 <table> |
|
59 <tr><td>None</td></tr> |
|
60 </table> |
|
61 <h3>Methods</h3> |
|
62 <table> |
|
63 <tr> |
|
64 <td><a href="#E5Cache.__init__">E5Cache</a></td> |
|
65 <td>Constructor</td> |
|
66 </tr><tr> |
|
67 <td><a href="#E5Cache.__adjustToSize">__adjustToSize</a></td> |
|
68 <td>Private method to adjust the cache to its size.</td> |
|
69 </tr><tr> |
|
70 <td><a href="#E5Cache.__moveLast">__moveLast</a></td> |
|
71 <td>Private method to move a cached item to the MRU position.</td> |
|
72 </tr><tr> |
|
73 <td><a href="#E5Cache.__pruneCache">__pruneCache</a></td> |
|
74 <td>Private slot to prune outdated cache entries and restart the timer.</td> |
|
75 </tr><tr> |
|
76 <td><a href="#E5Cache.add">add</a></td> |
|
77 <td>Public method to add an item to the cache.</td> |
|
78 </tr><tr> |
|
79 <td><a href="#E5Cache.clear">clear</a></td> |
|
80 <td>Public method to clear the cache.</td> |
|
81 </tr><tr> |
|
82 <td><a href="#E5Cache.get">get</a></td> |
|
83 <td>Public method to get an entry from the cache given its key.</td> |
|
84 </tr><tr> |
|
85 <td><a href="#E5Cache.getMaximumCacheTime">getMaximumCacheTime</a></td> |
|
86 <td>Public method to get the maximum time entries may exist in the cache.</td> |
|
87 </tr><tr> |
|
88 <td><a href="#E5Cache.getSize">getSize</a></td> |
|
89 <td>Public method to get the maximum size of the cache.</td> |
|
90 </tr><tr> |
|
91 <td><a href="#E5Cache.info">info</a></td> |
|
92 <td>Public method to get some information about the cache.</td> |
|
93 </tr><tr> |
|
94 <td><a href="#E5Cache.length">length</a></td> |
|
95 <td>Public method to get the current length of the cache.</td> |
|
96 </tr><tr> |
|
97 <td><a href="#E5Cache.remove">remove</a></td> |
|
98 <td>Public method to remove an item from the cache.</td> |
|
99 </tr><tr> |
|
100 <td><a href="#E5Cache.reset">reset</a></td> |
|
101 <td>Public method to reset the cache.</td> |
|
102 </tr><tr> |
|
103 <td><a href="#E5Cache.setMaximumCacheTime">setMaximumCacheTime</a></td> |
|
104 <td>Public method to set the maximum time entries may exist in the cache.</td> |
|
105 </tr><tr> |
|
106 <td><a href="#E5Cache.setSize">setSize</a></td> |
|
107 <td>Public method to change the maximum size of the cache.</td> |
|
108 </tr> |
|
109 </table> |
|
110 <h3>Static Methods</h3> |
|
111 <table> |
|
112 <tr><td>None</td></tr> |
|
113 </table> |
|
114 <a NAME="E5Cache.__init__" ID="E5Cache.__init__"></a> |
|
115 <h4>E5Cache (Constructor)</h4> |
|
116 <b>E5Cache</b>(<i>size=100</i>) |
|
117 <p> |
|
118 Constructor |
|
119 </p><dl> |
|
120 <dt><i>size</i> (int)</dt> |
|
121 <dd> |
|
122 maximum number of entries that may be stored in the cache |
|
123 </dd> |
|
124 </dl><a NAME="E5Cache.__adjustToSize" ID="E5Cache.__adjustToSize"></a> |
|
125 <h4>E5Cache.__adjustToSize</h4> |
|
126 <b>__adjustToSize</b>(<i></i>) |
|
127 <p> |
|
128 Private method to adjust the cache to its size. |
|
129 </p><a NAME="E5Cache.__moveLast" ID="E5Cache.__moveLast"></a> |
|
130 <h4>E5Cache.__moveLast</h4> |
|
131 <b>__moveLast</b>(<i>key</i>) |
|
132 <p> |
|
133 Private method to move a cached item to the MRU position. |
|
134 </p><dl> |
|
135 <dt><i>key</i> (any hashable type that can be used as a dict key)</dt> |
|
136 <dd> |
|
137 key of the item to be retrieved |
|
138 </dd> |
|
139 </dl><a NAME="E5Cache.__pruneCache" ID="E5Cache.__pruneCache"></a> |
|
140 <h4>E5Cache.__pruneCache</h4> |
|
141 <b>__pruneCache</b>(<i></i>) |
|
142 <p> |
|
143 Private slot to prune outdated cache entries and restart the timer. |
|
144 </p><a NAME="E5Cache.add" ID="E5Cache.add"></a> |
|
145 <h4>E5Cache.add</h4> |
|
146 <b>add</b>(<i>key, item</i>) |
|
147 <p> |
|
148 Public method to add an item to the cache. |
|
149 </p><p> |
|
150 If the key is already in use, the cached item is replaced by the new |
|
151 one given and is moved to the MRU position |
|
152 </p><dl> |
|
153 <dt><i>key</i> (any hashable type that can be used as a dict key)</dt> |
|
154 <dd> |
|
155 key of the item to be retrieved |
|
156 </dd><dt><i>item</i> (object)</dt> |
|
157 <dd> |
|
158 item to be cached under the given key |
|
159 </dd> |
|
160 </dl><a NAME="E5Cache.clear" ID="E5Cache.clear"></a> |
|
161 <h4>E5Cache.clear</h4> |
|
162 <b>clear</b>(<i></i>) |
|
163 <p> |
|
164 Public method to clear the cache. |
|
165 </p><a NAME="E5Cache.get" ID="E5Cache.get"></a> |
|
166 <h4>E5Cache.get</h4> |
|
167 <b>get</b>(<i>key</i>) |
|
168 <p> |
|
169 Public method to get an entry from the cache given its key. |
|
170 </p><p> |
|
171 If the key is present in the cache, it is moved to the MRU position. |
|
172 </p><dl> |
|
173 <dt><i>key</i> (any hashable type that can be used as a dict key)</dt> |
|
174 <dd> |
|
175 key of the item to be retrieved |
|
176 </dd> |
|
177 </dl><dl> |
|
178 <dt>Returns:</dt> |
|
179 <dd> |
|
180 cached item for the given key or None, if the key is not |
|
181 present |
|
182 </dd> |
|
183 </dl><dl> |
|
184 <dt>Return Type:</dt> |
|
185 <dd> |
|
186 object or None |
|
187 </dd> |
|
188 </dl><a NAME="E5Cache.getMaximumCacheTime" ID="E5Cache.getMaximumCacheTime"></a> |
|
189 <h4>E5Cache.getMaximumCacheTime</h4> |
|
190 <b>getMaximumCacheTime</b>(<i></i>) |
|
191 <p> |
|
192 Public method to get the maximum time entries may exist in the cache. |
|
193 </p><dl> |
|
194 <dt>Returns:</dt> |
|
195 <dd> |
|
196 maximum cache time in seconds |
|
197 </dd> |
|
198 </dl><dl> |
|
199 <dt>Return Type:</dt> |
|
200 <dd> |
|
201 int |
|
202 </dd> |
|
203 </dl><a NAME="E5Cache.getSize" ID="E5Cache.getSize"></a> |
|
204 <h4>E5Cache.getSize</h4> |
|
205 <b>getSize</b>(<i></i>) |
|
206 <p> |
|
207 Public method to get the maximum size of the cache. |
|
208 </p><dl> |
|
209 <dt>Returns:</dt> |
|
210 <dd> |
|
211 maximum number of entries of the cache |
|
212 </dd> |
|
213 </dl><dl> |
|
214 <dt>Return Type:</dt> |
|
215 <dd> |
|
216 int |
|
217 </dd> |
|
218 </dl><a NAME="E5Cache.info" ID="E5Cache.info"></a> |
|
219 <h4>E5Cache.info</h4> |
|
220 <b>info</b>(<i></i>) |
|
221 <p> |
|
222 Public method to get some information about the cache. |
|
223 </p><dl> |
|
224 <dt>Returns:</dt> |
|
225 <dd> |
|
226 dictionary containing the cache info |
|
227 </dd> |
|
228 </dl><dl> |
|
229 <dt>Return Type:</dt> |
|
230 <dd> |
|
231 dict (with keys "hits", "misses", "maxsize", "currsize") |
|
232 </dd> |
|
233 </dl><a NAME="E5Cache.length" ID="E5Cache.length"></a> |
|
234 <h4>E5Cache.length</h4> |
|
235 <b>length</b>(<i></i>) |
|
236 <p> |
|
237 Public method to get the current length of the cache. |
|
238 </p><dl> |
|
239 <dt>Returns:</dt> |
|
240 <dd> |
|
241 current length of the cache |
|
242 </dd> |
|
243 </dl><dl> |
|
244 <dt>Return Type:</dt> |
|
245 <dd> |
|
246 int |
|
247 </dd> |
|
248 </dl><a NAME="E5Cache.remove" ID="E5Cache.remove"></a> |
|
249 <h4>E5Cache.remove</h4> |
|
250 <b>remove</b>(<i>key</i>) |
|
251 <p> |
|
252 Public method to remove an item from the cache. |
|
253 </p><dl> |
|
254 <dt><i>key</i> (any hashable type that can be used as a dict key)</dt> |
|
255 <dd> |
|
256 key of the item to be retrieved |
|
257 </dd> |
|
258 </dl><a NAME="E5Cache.reset" ID="E5Cache.reset"></a> |
|
259 <h4>E5Cache.reset</h4> |
|
260 <b>reset</b>(<i></i>) |
|
261 <p> |
|
262 Public method to reset the cache. |
|
263 </p><p> |
|
264 This is like clear() but sets the various counters to their initial |
|
265 value as well. |
|
266 </p><a NAME="E5Cache.setMaximumCacheTime" ID="E5Cache.setMaximumCacheTime"></a> |
|
267 <h4>E5Cache.setMaximumCacheTime</h4> |
|
268 <b>setMaximumCacheTime</b>(<i>time</i>) |
|
269 <p> |
|
270 Public method to set the maximum time entries may exist in the cache. |
|
271 </p><dl> |
|
272 <dt><i>time</i> (int)</dt> |
|
273 <dd> |
|
274 maximum cache time in seconds |
|
275 </dd> |
|
276 </dl><a NAME="E5Cache.setSize" ID="E5Cache.setSize"></a> |
|
277 <h4>E5Cache.setSize</h4> |
|
278 <b>setSize</b>(<i>newSize</i>) |
|
279 <p> |
|
280 Public method to change the maximum size of the cache. |
|
281 </p><dl> |
|
282 <dt><i>newSize</i> (int)</dt> |
|
283 <dd> |
|
284 maximum number of entries that may be stored in the |
|
285 cache |
|
286 </dd> |
|
287 </dl> |
|
288 <div align="right"><a href="#top">Up</a></div> |
|
289 <hr /> |
|
290 </body></html> |