Fred Drake | 64bc94e | 1999-06-17 15:11:35 +0000 | [diff] [blame] | 1 | \section{\module{statcache} --- |
| 2 | An optimization of \function{os.stat()}} |
| 3 | |
| 4 | \declaremodule{standard}{statcache} |
| 5 | \sectionauthor{Moshe Zadka}{mzadka@geocities.com} |
| 6 | \modulesynopsis{Stat files, and remember results.} |
| 7 | |
| 8 | The \module{statcache} module provides a simple optimization to |
| 9 | \function{os.stat()}: remembering the values of previous invocations. |
| 10 | |
| 11 | The \module{statcache} module defines the following functions: |
| 12 | |
| 13 | \begin{funcdesc}{stat}{path} |
| 14 | This is the main module entry-point. |
| 15 | Identical for \function{os.stat()}, except for remembering the result |
| 16 | for future invocations of the function. |
| 17 | \end{funcdesc} |
| 18 | |
| 19 | The rest of the functions are used to clear the cache, or parts of |
| 20 | it. |
| 21 | |
| 22 | \begin{funcdesc}{reset}{} |
| 23 | Clear the cache: forget all results of previous \code{stat}s. |
| 24 | \end{funcdesc} |
| 25 | |
| 26 | \begin{funcdesc}{forget}{path} |
| 27 | Forget the result of \code{stat(\var{path})}, if any. |
| 28 | \end{funcdesc} |
| 29 | |
| 30 | \begin{funcdesc}{forget_prefix}{prefix} |
| 31 | Forget all results of \code{stat(\var{path})} for \var{path} starting |
| 32 | with \var{prefix}. |
| 33 | \end{funcdesc} |
| 34 | |
| 35 | \begin{funcdesc}{forget_dir}{prefix} |
| 36 | Forget all results of \code{stat(\var{path})} for \var{path} a file in |
| 37 | the directory \var{prefix}, including \code{stat(\var{prefix})}. |
| 38 | \end{funcdesc} |
| 39 | |
| 40 | \begin{funcdesc}{forget_except_prefix}{prefix} |
| 41 | Similar to \function{forget_prefix()}, but for all \var{path} |
| 42 | \emph{not} starting with \var{prefix}. |
| 43 | \end{funcdesc} |
| 44 | |
| 45 | Example: |
| 46 | |
| 47 | \begin{verbatim} |
| 48 | >>> import os, statcache |
| 49 | >>> statcache.stat('.') |
| 50 | (16893, 2049, 772, 18, 1000, 1000, 2048, 929609777, 929609777, 929609777) |
| 51 | >>> os.stat('.') |
| 52 | (16893, 2049, 772, 18, 1000, 1000, 2048, 929609777, 929609777, 929609777) |
| 53 | \end{verbatim} |