16 |
16 |
17 a { color: #BA6D36; } |
17 a { color: #BA6D36; } |
18 |
18 |
19 </style> |
19 </style> |
20 </head> |
20 </head> |
21 <body><a NAME="top" ID="top"></a> |
21 <body> |
|
22 <a NAME="top" ID="top"></a> |
22 <h1>eric6.E5Utilities.E5Cache</h1> |
23 <h1>eric6.E5Utilities.E5Cache</h1> |
|
24 |
23 <p> |
25 <p> |
24 Module implementing classes used for caching objects. |
26 Module implementing classes used for caching objects. |
25 </p> |
27 </p> |
26 <h3>Global Attributes</h3> |
28 <h3>Global Attributes</h3> |
|
29 |
27 <table> |
30 <table> |
28 <tr><td>None</td></tr> |
31 <tr><td>None</td></tr> |
29 </table> |
32 </table> |
30 <h3>Classes</h3> |
33 <h3>Classes</h3> |
31 <table> |
34 |
|
35 <table> |
|
36 |
32 <tr> |
37 <tr> |
33 <td><a href="#E5Cache">E5Cache</a></td> |
38 <td><a href="#E5Cache">E5Cache</a></td> |
34 <td>Class implementing a LRU cache of a specific size.</td> |
39 <td>Class implementing a LRU cache of a specific size.</td> |
35 </tr> |
40 </tr> |
36 </table> |
41 </table> |
37 <h3>Functions</h3> |
42 <h3>Functions</h3> |
38 <table> |
43 |
39 <tr><td>None</td></tr> |
44 <table> |
40 </table> |
45 <tr><td>None</td></tr> |
41 <hr /><hr /> |
46 </table> |
|
47 <hr /> |
|
48 <hr /> |
42 <a NAME="E5Cache" ID="E5Cache"></a> |
49 <a NAME="E5Cache" ID="E5Cache"></a> |
43 <h2>E5Cache</h2> |
50 <h2>E5Cache</h2> |
|
51 |
44 <p> |
52 <p> |
45 Class implementing a LRU cache of a specific size. |
53 Class implementing a LRU cache of a specific size. |
46 </p><p> |
54 </p> |
|
55 <p> |
47 If the maximum number of entries is exceeded, the least recently used item |
56 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 |
57 is removed from the cache. A cache hit moves the entry to the front of the |
49 cache. |
58 cache. |
50 </p> |
59 </p> |
51 <h3>Derived from</h3> |
60 <h3>Derived from</h3> |
52 object |
61 object |
53 <h3>Class Attributes</h3> |
62 <h3>Class Attributes</h3> |
|
63 |
54 <table> |
64 <table> |
55 <tr><td>None</td></tr> |
65 <tr><td>None</td></tr> |
56 </table> |
66 </table> |
57 <h3>Class Methods</h3> |
67 <h3>Class Methods</h3> |
|
68 |
58 <table> |
69 <table> |
59 <tr><td>None</td></tr> |
70 <tr><td>None</td></tr> |
60 </table> |
71 </table> |
61 <h3>Methods</h3> |
72 <h3>Methods</h3> |
62 <table> |
73 |
|
74 <table> |
|
75 |
63 <tr> |
76 <tr> |
64 <td><a href="#E5Cache.__init__">E5Cache</a></td> |
77 <td><a href="#E5Cache.__init__">E5Cache</a></td> |
65 <td>Constructor</td> |
78 <td>Constructor</td> |
66 </tr><tr> |
79 </tr> |
|
80 <tr> |
67 <td><a href="#E5Cache.__adjustToSize">__adjustToSize</a></td> |
81 <td><a href="#E5Cache.__adjustToSize">__adjustToSize</a></td> |
68 <td>Private method to adjust the cache to its size.</td> |
82 <td>Private method to adjust the cache to its size.</td> |
69 </tr><tr> |
83 </tr> |
|
84 <tr> |
70 <td><a href="#E5Cache.__moveLast">__moveLast</a></td> |
85 <td><a href="#E5Cache.__moveLast">__moveLast</a></td> |
71 <td>Private method to move a cached item to the MRU position.</td> |
86 <td>Private method to move a cached item to the MRU position.</td> |
72 </tr><tr> |
87 </tr> |
|
88 <tr> |
73 <td><a href="#E5Cache.__pruneCache">__pruneCache</a></td> |
89 <td><a href="#E5Cache.__pruneCache">__pruneCache</a></td> |
74 <td>Private slot to prune outdated cache entries and restart the timer.</td> |
90 <td>Private slot to prune outdated cache entries and restart the timer.</td> |
75 </tr><tr> |
91 </tr> |
|
92 <tr> |
76 <td><a href="#E5Cache.add">add</a></td> |
93 <td><a href="#E5Cache.add">add</a></td> |
77 <td>Public method to add an item to the cache.</td> |
94 <td>Public method to add an item to the cache.</td> |
78 </tr><tr> |
95 </tr> |
|
96 <tr> |
79 <td><a href="#E5Cache.clear">clear</a></td> |
97 <td><a href="#E5Cache.clear">clear</a></td> |
80 <td>Public method to clear the cache.</td> |
98 <td>Public method to clear the cache.</td> |
81 </tr><tr> |
99 </tr> |
|
100 <tr> |
82 <td><a href="#E5Cache.get">get</a></td> |
101 <td><a href="#E5Cache.get">get</a></td> |
83 <td>Public method to get an entry from the cache given its key.</td> |
102 <td>Public method to get an entry from the cache given its key.</td> |
84 </tr><tr> |
103 </tr> |
|
104 <tr> |
85 <td><a href="#E5Cache.getMaximumCacheTime">getMaximumCacheTime</a></td> |
105 <td><a href="#E5Cache.getMaximumCacheTime">getMaximumCacheTime</a></td> |
86 <td>Public method to get the maximum time entries may exist in the cache.</td> |
106 <td>Public method to get the maximum time entries may exist in the cache.</td> |
87 </tr><tr> |
107 </tr> |
|
108 <tr> |
88 <td><a href="#E5Cache.getSize">getSize</a></td> |
109 <td><a href="#E5Cache.getSize">getSize</a></td> |
89 <td>Public method to get the maximum size of the cache.</td> |
110 <td>Public method to get the maximum size of the cache.</td> |
90 </tr><tr> |
111 </tr> |
|
112 <tr> |
91 <td><a href="#E5Cache.info">info</a></td> |
113 <td><a href="#E5Cache.info">info</a></td> |
92 <td>Public method to get some information about the cache.</td> |
114 <td>Public method to get some information about the cache.</td> |
93 </tr><tr> |
115 </tr> |
|
116 <tr> |
94 <td><a href="#E5Cache.length">length</a></td> |
117 <td><a href="#E5Cache.length">length</a></td> |
95 <td>Public method to get the current length of the cache.</td> |
118 <td>Public method to get the current length of the cache.</td> |
96 </tr><tr> |
119 </tr> |
|
120 <tr> |
97 <td><a href="#E5Cache.remove">remove</a></td> |
121 <td><a href="#E5Cache.remove">remove</a></td> |
98 <td>Public method to remove an item from the cache.</td> |
122 <td>Public method to remove an item from the cache.</td> |
99 </tr><tr> |
123 </tr> |
|
124 <tr> |
100 <td><a href="#E5Cache.reset">reset</a></td> |
125 <td><a href="#E5Cache.reset">reset</a></td> |
101 <td>Public method to reset the cache.</td> |
126 <td>Public method to reset the cache.</td> |
102 </tr><tr> |
127 </tr> |
|
128 <tr> |
103 <td><a href="#E5Cache.setMaximumCacheTime">setMaximumCacheTime</a></td> |
129 <td><a href="#E5Cache.setMaximumCacheTime">setMaximumCacheTime</a></td> |
104 <td>Public method to set the maximum time entries may exist in the cache.</td> |
130 <td>Public method to set the maximum time entries may exist in the cache.</td> |
105 </tr><tr> |
131 </tr> |
|
132 <tr> |
106 <td><a href="#E5Cache.setSize">setSize</a></td> |
133 <td><a href="#E5Cache.setSize">setSize</a></td> |
107 <td>Public method to change the maximum size of the cache.</td> |
134 <td>Public method to change the maximum size of the cache.</td> |
108 </tr> |
135 </tr> |
109 </table> |
136 </table> |
110 <h3>Static Methods</h3> |
137 <h3>Static Methods</h3> |
111 <table> |
138 |
112 <tr><td>None</td></tr> |
139 <table> |
113 </table> |
140 <tr><td>None</td></tr> |
|
141 </table> |
|
142 |
114 <a NAME="E5Cache.__init__" ID="E5Cache.__init__"></a> |
143 <a NAME="E5Cache.__init__" ID="E5Cache.__init__"></a> |
115 <h4>E5Cache (Constructor)</h4> |
144 <h4>E5Cache (Constructor)</h4> |
116 <b>E5Cache</b>(<i>size=100</i>) |
145 <b>E5Cache</b>(<i>size=100</i>) |
|
146 |
117 <p> |
147 <p> |
118 Constructor |
148 Constructor |
119 </p><dl> |
149 </p> |
|
150 <dl> |
|
151 |
120 <dt><i>size</i> (int)</dt> |
152 <dt><i>size</i> (int)</dt> |
121 <dd> |
153 <dd> |
122 maximum number of entries that may be stored in the cache |
154 maximum number of entries that may be stored in the cache |
123 </dd> |
155 </dd> |
124 </dl><a NAME="E5Cache.__adjustToSize" ID="E5Cache.__adjustToSize"></a> |
156 </dl> |
|
157 <a NAME="E5Cache.__adjustToSize" ID="E5Cache.__adjustToSize"></a> |
125 <h4>E5Cache.__adjustToSize</h4> |
158 <h4>E5Cache.__adjustToSize</h4> |
126 <b>__adjustToSize</b>(<i></i>) |
159 <b>__adjustToSize</b>(<i></i>) |
|
160 |
127 <p> |
161 <p> |
128 Private method to adjust the cache to its size. |
162 Private method to adjust the cache to its size. |
129 </p><a NAME="E5Cache.__moveLast" ID="E5Cache.__moveLast"></a> |
163 </p> |
|
164 <a NAME="E5Cache.__moveLast" ID="E5Cache.__moveLast"></a> |
130 <h4>E5Cache.__moveLast</h4> |
165 <h4>E5Cache.__moveLast</h4> |
131 <b>__moveLast</b>(<i>key</i>) |
166 <b>__moveLast</b>(<i>key</i>) |
|
167 |
132 <p> |
168 <p> |
133 Private method to move a cached item to the MRU position. |
169 Private method to move a cached item to the MRU position. |
134 </p><dl> |
170 </p> |
|
171 <dl> |
|
172 |
135 <dt><i>key</i> (any hashable type that can be used as a dict key)</dt> |
173 <dt><i>key</i> (any hashable type that can be used as a dict key)</dt> |
136 <dd> |
174 <dd> |
137 key of the item to be retrieved |
175 key of the item to be retrieved |
138 </dd> |
176 </dd> |
139 </dl><a NAME="E5Cache.__pruneCache" ID="E5Cache.__pruneCache"></a> |
177 </dl> |
|
178 <a NAME="E5Cache.__pruneCache" ID="E5Cache.__pruneCache"></a> |
140 <h4>E5Cache.__pruneCache</h4> |
179 <h4>E5Cache.__pruneCache</h4> |
141 <b>__pruneCache</b>(<i></i>) |
180 <b>__pruneCache</b>(<i></i>) |
|
181 |
142 <p> |
182 <p> |
143 Private slot to prune outdated cache entries and restart the timer. |
183 Private slot to prune outdated cache entries and restart the timer. |
144 </p><a NAME="E5Cache.add" ID="E5Cache.add"></a> |
184 </p> |
|
185 <a NAME="E5Cache.add" ID="E5Cache.add"></a> |
145 <h4>E5Cache.add</h4> |
186 <h4>E5Cache.add</h4> |
146 <b>add</b>(<i>key, item</i>) |
187 <b>add</b>(<i>key, item</i>) |
|
188 |
147 <p> |
189 <p> |
148 Public method to add an item to the cache. |
190 Public method to add an item to the cache. |
149 </p><p> |
191 </p> |
|
192 <p> |
150 If the key is already in use, the cached item is replaced by the new |
193 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 |
194 one given and is moved to the MRU position |
152 </p><dl> |
195 </p> |
|
196 <dl> |
|
197 |
153 <dt><i>key</i> (any hashable type that can be used as a dict key)</dt> |
198 <dt><i>key</i> (any hashable type that can be used as a dict key)</dt> |
154 <dd> |
199 <dd> |
155 key of the item to be retrieved |
200 key of the item to be retrieved |
156 </dd><dt><i>item</i> (object)</dt> |
201 </dd> |
|
202 <dt><i>item</i> (object)</dt> |
157 <dd> |
203 <dd> |
158 item to be cached under the given key |
204 item to be cached under the given key |
159 </dd> |
205 </dd> |
160 </dl><a NAME="E5Cache.clear" ID="E5Cache.clear"></a> |
206 </dl> |
|
207 <a NAME="E5Cache.clear" ID="E5Cache.clear"></a> |
161 <h4>E5Cache.clear</h4> |
208 <h4>E5Cache.clear</h4> |
162 <b>clear</b>(<i></i>) |
209 <b>clear</b>(<i></i>) |
|
210 |
163 <p> |
211 <p> |
164 Public method to clear the cache. |
212 Public method to clear the cache. |
165 </p><a NAME="E5Cache.get" ID="E5Cache.get"></a> |
213 </p> |
|
214 <a NAME="E5Cache.get" ID="E5Cache.get"></a> |
166 <h4>E5Cache.get</h4> |
215 <h4>E5Cache.get</h4> |
167 <b>get</b>(<i>key</i>) |
216 <b>get</b>(<i>key</i>) |
|
217 |
168 <p> |
218 <p> |
169 Public method to get an entry from the cache given its key. |
219 Public method to get an entry from the cache given its key. |
170 </p><p> |
220 </p> |
|
221 <p> |
171 If the key is present in the cache, it is moved to the MRU position. |
222 If the key is present in the cache, it is moved to the MRU position. |
172 </p><dl> |
223 </p> |
|
224 <dl> |
|
225 |
173 <dt><i>key</i> (any hashable type that can be used as a dict key)</dt> |
226 <dt><i>key</i> (any hashable type that can be used as a dict key)</dt> |
174 <dd> |
227 <dd> |
175 key of the item to be retrieved |
228 key of the item to be retrieved |
176 </dd> |
229 </dd> |
177 </dl><dl> |
230 </dl> |
|
231 <dl> |
178 <dt>Returns:</dt> |
232 <dt>Returns:</dt> |
179 <dd> |
233 <dd> |
180 cached item for the given key or None, if the key is not |
234 cached item for the given key or None, if the key is not |
181 present |
235 present |
182 </dd> |
236 </dd> |
183 </dl><dl> |
237 </dl> |
|
238 <dl> |
184 <dt>Return Type:</dt> |
239 <dt>Return Type:</dt> |
185 <dd> |
240 <dd> |
186 object or None |
241 object or None |
187 </dd> |
242 </dd> |
188 </dl><a NAME="E5Cache.getMaximumCacheTime" ID="E5Cache.getMaximumCacheTime"></a> |
243 </dl> |
|
244 <a NAME="E5Cache.getMaximumCacheTime" ID="E5Cache.getMaximumCacheTime"></a> |
189 <h4>E5Cache.getMaximumCacheTime</h4> |
245 <h4>E5Cache.getMaximumCacheTime</h4> |
190 <b>getMaximumCacheTime</b>(<i></i>) |
246 <b>getMaximumCacheTime</b>(<i></i>) |
|
247 |
191 <p> |
248 <p> |
192 Public method to get the maximum time entries may exist in the cache. |
249 Public method to get the maximum time entries may exist in the cache. |
193 </p><dl> |
250 </p> |
|
251 <dl> |
194 <dt>Returns:</dt> |
252 <dt>Returns:</dt> |
195 <dd> |
253 <dd> |
196 maximum cache time in seconds |
254 maximum cache time in seconds |
197 </dd> |
255 </dd> |
198 </dl><dl> |
256 </dl> |
|
257 <dl> |
199 <dt>Return Type:</dt> |
258 <dt>Return Type:</dt> |
200 <dd> |
259 <dd> |
201 int |
260 int |
202 </dd> |
261 </dd> |
203 </dl><a NAME="E5Cache.getSize" ID="E5Cache.getSize"></a> |
262 </dl> |
|
263 <a NAME="E5Cache.getSize" ID="E5Cache.getSize"></a> |
204 <h4>E5Cache.getSize</h4> |
264 <h4>E5Cache.getSize</h4> |
205 <b>getSize</b>(<i></i>) |
265 <b>getSize</b>(<i></i>) |
|
266 |
206 <p> |
267 <p> |
207 Public method to get the maximum size of the cache. |
268 Public method to get the maximum size of the cache. |
208 </p><dl> |
269 </p> |
|
270 <dl> |
209 <dt>Returns:</dt> |
271 <dt>Returns:</dt> |
210 <dd> |
272 <dd> |
211 maximum number of entries of the cache |
273 maximum number of entries of the cache |
212 </dd> |
274 </dd> |
213 </dl><dl> |
275 </dl> |
|
276 <dl> |
214 <dt>Return Type:</dt> |
277 <dt>Return Type:</dt> |
215 <dd> |
278 <dd> |
216 int |
279 int |
217 </dd> |
280 </dd> |
218 </dl><a NAME="E5Cache.info" ID="E5Cache.info"></a> |
281 </dl> |
|
282 <a NAME="E5Cache.info" ID="E5Cache.info"></a> |
219 <h4>E5Cache.info</h4> |
283 <h4>E5Cache.info</h4> |
220 <b>info</b>(<i></i>) |
284 <b>info</b>(<i></i>) |
|
285 |
221 <p> |
286 <p> |
222 Public method to get some information about the cache. |
287 Public method to get some information about the cache. |
223 </p><dl> |
288 </p> |
|
289 <dl> |
224 <dt>Returns:</dt> |
290 <dt>Returns:</dt> |
225 <dd> |
291 <dd> |
226 dictionary containing the cache info |
292 dictionary containing the cache info |
227 </dd> |
293 </dd> |
228 </dl><dl> |
294 </dl> |
|
295 <dl> |
229 <dt>Return Type:</dt> |
296 <dt>Return Type:</dt> |
230 <dd> |
297 <dd> |
231 dict (with keys "hits", "misses", "maxsize", "currsize") |
298 dict (with keys "hits", "misses", "maxsize", "currsize") |
232 </dd> |
299 </dd> |
233 </dl><a NAME="E5Cache.length" ID="E5Cache.length"></a> |
300 </dl> |
|
301 <a NAME="E5Cache.length" ID="E5Cache.length"></a> |
234 <h4>E5Cache.length</h4> |
302 <h4>E5Cache.length</h4> |
235 <b>length</b>(<i></i>) |
303 <b>length</b>(<i></i>) |
|
304 |
236 <p> |
305 <p> |
237 Public method to get the current length of the cache. |
306 Public method to get the current length of the cache. |
238 </p><dl> |
307 </p> |
|
308 <dl> |
239 <dt>Returns:</dt> |
309 <dt>Returns:</dt> |
240 <dd> |
310 <dd> |
241 current length of the cache |
311 current length of the cache |
242 </dd> |
312 </dd> |
243 </dl><dl> |
313 </dl> |
|
314 <dl> |
244 <dt>Return Type:</dt> |
315 <dt>Return Type:</dt> |
245 <dd> |
316 <dd> |
246 int |
317 int |
247 </dd> |
318 </dd> |
248 </dl><a NAME="E5Cache.remove" ID="E5Cache.remove"></a> |
319 </dl> |
|
320 <a NAME="E5Cache.remove" ID="E5Cache.remove"></a> |
249 <h4>E5Cache.remove</h4> |
321 <h4>E5Cache.remove</h4> |
250 <b>remove</b>(<i>key</i>) |
322 <b>remove</b>(<i>key</i>) |
|
323 |
251 <p> |
324 <p> |
252 Public method to remove an item from the cache. |
325 Public method to remove an item from the cache. |
253 </p><dl> |
326 </p> |
|
327 <dl> |
|
328 |
254 <dt><i>key</i> (any hashable type that can be used as a dict key)</dt> |
329 <dt><i>key</i> (any hashable type that can be used as a dict key)</dt> |
255 <dd> |
330 <dd> |
256 key of the item to be retrieved |
331 key of the item to be retrieved |
257 </dd> |
332 </dd> |
258 </dl><a NAME="E5Cache.reset" ID="E5Cache.reset"></a> |
333 </dl> |
|
334 <a NAME="E5Cache.reset" ID="E5Cache.reset"></a> |
259 <h4>E5Cache.reset</h4> |
335 <h4>E5Cache.reset</h4> |
260 <b>reset</b>(<i></i>) |
336 <b>reset</b>(<i></i>) |
|
337 |
261 <p> |
338 <p> |
262 Public method to reset the cache. |
339 Public method to reset the cache. |
263 </p><p> |
340 </p> |
|
341 <p> |
264 This is like clear() but sets the various counters to their initial |
342 This is like clear() but sets the various counters to their initial |
265 value as well. |
343 value as well. |
266 </p><a NAME="E5Cache.setMaximumCacheTime" ID="E5Cache.setMaximumCacheTime"></a> |
344 </p> |
|
345 <a NAME="E5Cache.setMaximumCacheTime" ID="E5Cache.setMaximumCacheTime"></a> |
267 <h4>E5Cache.setMaximumCacheTime</h4> |
346 <h4>E5Cache.setMaximumCacheTime</h4> |
268 <b>setMaximumCacheTime</b>(<i>time</i>) |
347 <b>setMaximumCacheTime</b>(<i>time</i>) |
|
348 |
269 <p> |
349 <p> |
270 Public method to set the maximum time entries may exist in the cache. |
350 Public method to set the maximum time entries may exist in the cache. |
271 </p><dl> |
351 </p> |
|
352 <dl> |
|
353 |
272 <dt><i>time</i> (int)</dt> |
354 <dt><i>time</i> (int)</dt> |
273 <dd> |
355 <dd> |
274 maximum cache time in seconds |
356 maximum cache time in seconds |
275 </dd> |
357 </dd> |
276 </dl><a NAME="E5Cache.setSize" ID="E5Cache.setSize"></a> |
358 </dl> |
|
359 <a NAME="E5Cache.setSize" ID="E5Cache.setSize"></a> |
277 <h4>E5Cache.setSize</h4> |
360 <h4>E5Cache.setSize</h4> |
278 <b>setSize</b>(<i>newSize</i>) |
361 <b>setSize</b>(<i>newSize</i>) |
|
362 |
279 <p> |
363 <p> |
280 Public method to change the maximum size of the cache. |
364 Public method to change the maximum size of the cache. |
281 </p><dl> |
365 </p> |
|
366 <dl> |
|
367 |
282 <dt><i>newSize</i> (int)</dt> |
368 <dt><i>newSize</i> (int)</dt> |
283 <dd> |
369 <dd> |
284 maximum number of entries that may be stored in the |
370 maximum number of entries that may be stored in the |
285 cache |
371 cache |
286 </dd> |
372 </dd> |