Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-statvfs.html" /> | |
13 | <link rel="prev" href="module-stat.html" /> | |
14 | <link rel="parent" href="allos.html" /> | |
15 | <link rel="next" href="module-statvfs.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>6.5 statcache -- An optimization of os.stat()</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="6.4 stat " | |
25 | href="module-stat.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="6. Generic Operating System" | |
28 | href="allos.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="6.6 statvfs " | |
31 | href="module-statvfs.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="module-stat.html">6.4 stat </A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="allos.html">6. Generic Operating System</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="module-statvfs.html">6.6 statvfs </A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION008500000000000000000"> | |
56 | 6.5 <tt class="module">statcache</tt> -- | |
57 | An optimization of <tt class="function">os.stat()</tt></A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-statcache"></A> | |
62 | ||
63 | <P> | |
64 | <div class="versionnote"><b>Deprecated since release 2.2.</b> | |
65 | Use <tt class="function"><tt class="module"><a href="module-os.html">os</a></tt>.stat()</tt> directly instead | |
66 | of using the cache; the cache introduces a very high level of | |
67 | fragility in applications using it and complicates application code | |
68 | with the addition of cache management support.</div><p></p> | |
69 | ||
70 | <P> | |
71 | The <tt class="module">statcache</tt> module provides a simple optimization to | |
72 | <tt class="function">os.stat()</tt>: remembering the values of previous invocations. | |
73 | ||
74 | <P> | |
75 | The <tt class="module">statcache</tt> module defines the following functions: | |
76 | ||
77 | <P> | |
78 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
79 | <td><nobr><b><tt id='l2h-1796' xml:id='l2h-1796' class="function">stat</tt></b>(</nobr></td> | |
80 | <td><var>path</var>)</td></tr></table></dt> | |
81 | <dd> | |
82 | This is the main module entry-point. | |
83 | Identical for <tt class="function">os.stat()</tt>, except for remembering the result | |
84 | for future invocations of the function. | |
85 | </dl> | |
86 | ||
87 | <P> | |
88 | The rest of the functions are used to clear the cache, or parts of | |
89 | it. | |
90 | ||
91 | <P> | |
92 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
93 | <td><nobr><b><tt id='l2h-1797' xml:id='l2h-1797' class="function">reset</tt></b>(</nobr></td> | |
94 | <td><var></var>)</td></tr></table></dt> | |
95 | <dd> | |
96 | Clear the cache: forget all results of previous <tt class="function">stat()</tt> | |
97 | calls. | |
98 | </dl> | |
99 | ||
100 | <P> | |
101 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
102 | <td><nobr><b><tt id='l2h-1798' xml:id='l2h-1798' class="function">forget</tt></b>(</nobr></td> | |
103 | <td><var>path</var>)</td></tr></table></dt> | |
104 | <dd> | |
105 | Forget the result of <code>stat(<var>path</var>)</code>, if any. | |
106 | </dl> | |
107 | ||
108 | <P> | |
109 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
110 | <td><nobr><b><tt id='l2h-1799' xml:id='l2h-1799' class="function">forget_prefix</tt></b>(</nobr></td> | |
111 | <td><var>prefix</var>)</td></tr></table></dt> | |
112 | <dd> | |
113 | Forget all results of <code>stat(<var>path</var>)</code> for <var>path</var> starting | |
114 | with <var>prefix</var>. | |
115 | </dl> | |
116 | ||
117 | <P> | |
118 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
119 | <td><nobr><b><tt id='l2h-1800' xml:id='l2h-1800' class="function">forget_dir</tt></b>(</nobr></td> | |
120 | <td><var>prefix</var>)</td></tr></table></dt> | |
121 | <dd> | |
122 | Forget all results of <code>stat(<var>path</var>)</code> for <var>path</var> a file in | |
123 | the directory <var>prefix</var>, including <code>stat(<var>prefix</var>)</code>. | |
124 | </dl> | |
125 | ||
126 | <P> | |
127 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
128 | <td><nobr><b><tt id='l2h-1801' xml:id='l2h-1801' class="function">forget_except_prefix</tt></b>(</nobr></td> | |
129 | <td><var>prefix</var>)</td></tr></table></dt> | |
130 | <dd> | |
131 | Similar to <tt class="function">forget_prefix()</tt>, but for all <var>path</var> values | |
132 | <em>not</em> starting with <var>prefix</var>. | |
133 | </dl> | |
134 | ||
135 | <P> | |
136 | Example: | |
137 | ||
138 | <P> | |
139 | <div class="verbatim"><pre> | |
140 | >>> import os, statcache | |
141 | >>> statcache.stat('.') | |
142 | (16893, 2049, 772, 18, 1000, 1000, 2048, 929609777, 929609777, 929609777) | |
143 | >>> os.stat('.') | |
144 | (16893, 2049, 772, 18, 1000, 1000, 2048, 929609777, 929609777, 929609777) | |
145 | </pre></div> | |
146 | ||
147 | <DIV CLASS="navigation"> | |
148 | <div class='online-navigation'> | |
149 | <p></p><hr /> | |
150 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
151 | <tr> | |
152 | <td class='online-navigation'><a rel="prev" title="6.4 stat " | |
153 | href="module-stat.html"><img src='../icons/previous.png' | |
154 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
155 | <td class='online-navigation'><a rel="parent" title="6. Generic Operating System" | |
156 | href="allos.html"><img src='../icons/up.png' | |
157 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
158 | <td class='online-navigation'><a rel="next" title="6.6 statvfs " | |
159 | href="module-statvfs.html"><img src='../icons/next.png' | |
160 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
161 | <td align="center" width="100%">Python Library Reference</td> | |
162 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
163 | href="contents.html"><img src='../icons/contents.png' | |
164 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
165 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
166 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
167 | <td class='online-navigation'><a rel="index" title="Index" | |
168 | href="genindex.html"><img src='../icons/index.png' | |
169 | border='0' height='32' alt='Index' width='32' /></A></td> | |
170 | </tr></table> | |
171 | <div class='online-navigation'> | |
172 | <b class="navlabel">Previous:</b> | |
173 | <a class="sectref" rel="prev" href="module-stat.html">6.4 stat </A> | |
174 | <b class="navlabel">Up:</b> | |
175 | <a class="sectref" rel="parent" href="allos.html">6. Generic Operating System</A> | |
176 | <b class="navlabel">Next:</b> | |
177 | <a class="sectref" rel="next" href="module-statvfs.html">6.6 statvfs </A> | |
178 | </div> | |
179 | </div> | |
180 | <hr /> | |
181 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
182 | </DIV> | |
183 | <!--End of Navigation Panel--> | |
184 | <ADDRESS> | |
185 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
186 | </ADDRESS> | |
187 | </BODY> | |
188 | </HTML> |