1CHI::Driver::File(3) User Contributed Perl Documentation CHI::Driver::File(3)
2
3
4
6 CHI::Driver::File - File-based cache using one file per entry in a
7 multi-level directory structure
8
10 version 0.60
11
13 use CHI;
14
15 my $cache = CHI->new(
16 driver => 'File',
17 root_dir => '/path/to/cache/root',
18 depth => 3,
19 max_key_length => 64
20 );
21
23 This cache driver stores data on the filesystem, so that it can be
24 shared between processes on a single machine, or even on multiple
25 machines if using NFS.
26
27 Each item is stored in its own file. By default, during a set, a
28 temporary file is created and then atomically renamed to the proper
29 file. While not the most efficient, it eliminates the need for locking
30 (with multiple overlapping sets, the last one "wins") and makes this
31 cache usable in environments like NFS where locking might normally be
32 undesirable.
33
34 By default, the base filename is the key itself, with unsafe characters
35 escaped similar to URL escaping. If the escaped key is larger than
36 "max_key_length" (default 248 characters), it will be digested. You may
37 want to lower "max_key_length" if you are storing a lot of items as
38 long filenames can be more expensive to work with.
39
40 The files are evenly distributed within a multi-level directory
41 structure with a customizable "depth", to minimize the time needed to
42 search for a given entry.
43
45 When using this driver, the following options can be passed to
46 CHI->new() in addition to the CHI.
47
48 root_dir
49 The location in the filesystem that will hold the root of the
50 cache. Defaults to a directory called 'chi-driver-file' under the
51 OS default temp directory (e.g. '/tmp' on UNIX). This directory
52 will be created as needed on the first cache set.
53
54 depth
55 The number of subdirectories deep to place cache files. Defaults to
56 2. This should be large enough that no leaf directory has more than
57 a few hundred files. Each non-leaf directory contains up to 16
58 subdirectories (0-9, A-F).
59
60 dir_create_mode
61 Permissions mode to use when creating directories. Defaults to
62 0775.
63
64 file_create_mode
65 Permissions mode to use when creating files, modified by the
66 current umask. Defaults to 0666.
67
68 file_extension
69 Extension to append to filename. Default is ".dat".
70
72 path_to_key ( $key )
73 Returns the full path to the cache file representing $key, whether
74 or not that entry exists. Returns the empty list if a valid path
75 cannot be computed, for example if the key is too long.
76
77 path_to_namespace
78 Returns the full path to the directory representing this cache's
79 namespace, whether or not it has any entries.
80
82 By default, during a set, a temporary file is created and then
83 atomically renamed to the proper file. This eliminates the need for
84 locking. You can subclass and override method
85 generate_temporary_filename to either change the path of the temporary
86 filename, or skip the temporary file and rename altogether by having it
87 return undef.
88
90 CHI
91
93 Jonathan Swartz <swartz@pobox.com>
94
96 This software is copyright (c) 2012 by Jonathan Swartz.
97
98 This is free software; you can redistribute it and/or modify it under
99 the same terms as the Perl 5 programming language system itself.
100
101
102
103perl v5.30.0 2019-07-26 CHI::Driver::File(3)