blob: 3e7aaa3064ef7efc0367d77a84f2c0898eef84c2 [file] [log] [blame]
Fred Drake64bc94e1999-06-17 15:11:35 +00001\section{\module{statcache} ---
2 An optimization of \function{os.stat()}}
3
4\declaremodule{standard}{statcache}
Fred Drake57657bc2000-12-01 15:25:23 +00005\sectionauthor{Moshe Zadka}{moshez@zadka.site.co.il}
Fred Drake64bc94e1999-06-17 15:11:35 +00006\modulesynopsis{Stat files, and remember results.}
7
Fred Draked9272d62001-11-02 20:20:19 +00008
9\deprecated{2.2}{Use \function{\refmodule{os}.stat()} directly instead
10of using the cache; the cache introduces a very high level of
11fragility in applications using it and complicates application code
12with the addition of cache management support.}
13
Fred Drake64bc94e1999-06-17 15:11:35 +000014The \module{statcache} module provides a simple optimization to
15\function{os.stat()}: remembering the values of previous invocations.
16
17The \module{statcache} module defines the following functions:
18
19\begin{funcdesc}{stat}{path}
20This is the main module entry-point.
21Identical for \function{os.stat()}, except for remembering the result
22for future invocations of the function.
23\end{funcdesc}
24
25The rest of the functions are used to clear the cache, or parts of
26it.
27
28\begin{funcdesc}{reset}{}
Fred Drake173ba5e1999-06-17 17:09:23 +000029Clear the cache: forget all results of previous \function{stat()}
30calls.
Fred Drake64bc94e1999-06-17 15:11:35 +000031\end{funcdesc}
32
33\begin{funcdesc}{forget}{path}
34Forget the result of \code{stat(\var{path})}, if any.
35\end{funcdesc}
36
37\begin{funcdesc}{forget_prefix}{prefix}
38Forget all results of \code{stat(\var{path})} for \var{path} starting
39with \var{prefix}.
40\end{funcdesc}
41
42\begin{funcdesc}{forget_dir}{prefix}
Fred Drake173ba5e1999-06-17 17:09:23 +000043Forget all results of \code{stat(\var{path})} for \var{path} a file in
Fred Drake64bc94e1999-06-17 15:11:35 +000044the directory \var{prefix}, including \code{stat(\var{prefix})}.
45\end{funcdesc}
46
47\begin{funcdesc}{forget_except_prefix}{prefix}
Fred Drake173ba5e1999-06-17 17:09:23 +000048Similar to \function{forget_prefix()}, but for all \var{path} values
Fred Drake64bc94e1999-06-17 15:11:35 +000049\emph{not} starting with \var{prefix}.
50\end{funcdesc}
51
52Example:
53
54\begin{verbatim}
55>>> import os, statcache
56>>> statcache.stat('.')
57(16893, 2049, 772, 18, 1000, 1000, 2048, 929609777, 929609777, 929609777)
58>>> os.stat('.')
59(16893, 2049, 772, 18, 1000, 1000, 2048, 929609777, 929609777, 929609777)
60\end{verbatim}