| Code Coverage
| Lines | Functions and Methods | Classes and Traits
Total |  | n/a | 0 / 0 |  | n/a | 0 / 0 | CRAP |  | n/a | 0 / 0
Cache |  | n/a | 0 / 0 |  | n/a | 0 / 0 | 0 |  | n/a | 0 / 0

1 | <?php
2 |
3 | namespace Config;
4 |
5 | use CodeIgniter\Cache\CacheInterface;
6 | use CodeIgniter\Cache\Handlers\ApcuHandler;
7 | use CodeIgniter\Cache\Handlers\DummyHandler;
8 | use CodeIgniter\Cache\Handlers\FileHandler;
9 | use CodeIgniter\Cache\Handlers\MemcachedHandler;
10 | use CodeIgniter\Cache\Handlers\PredisHandler;
11 | use CodeIgniter\Cache\Handlers\RedisHandler;
12 | use CodeIgniter\Cache\Handlers\WincacheHandler;
13 | use CodeIgniter\Config\BaseConfig;
14 |
15 | class Cache extends BaseConfig
16 | {
17 | /**
18 | * --------------------------------------------------------------------------
19 | * Primary Handler
20 | * --------------------------------------------------------------------------
21 | *
22 | * The name of the preferred handler that should be used. If for some reason
23 | * it is not available, the $backupHandler will be used in its place.
24 | */
25 | public string $handler = 'file';
26 |
27 | /**
28 | * --------------------------------------------------------------------------
29 | * Backup Handler
30 | * --------------------------------------------------------------------------
31 | *
32 | * The name of the handler that will be used in case the first one is
33 | * unreachable. Often, 'file' is used here since the filesystem is
34 | * always available, though that's not always practical for the app.
35 | */
36 | public string $backupHandler = 'dummy';
37 |
38 | /**
39 | * --------------------------------------------------------------------------
40 | * Key Prefix
41 | * --------------------------------------------------------------------------
42 | *
43 | * This string is added to all cache item names to help avoid collisions
44 | * if you run multiple applications with the same cache engine.
45 | */
46 | public string $prefix = '';
47 |
48 | /**
49 | * --------------------------------------------------------------------------
50 | * Default TTL
51 | * --------------------------------------------------------------------------
52 | *
53 | * The default number of seconds to save items when none is specified.
54 | *
55 | * WARNING: This is not used by framework handlers where 60 seconds is
56 | * hard-coded, but may be useful to projects and modules. This will replace
57 | * the hard-coded value in a future release.
58 | */
59 | public int $ttl = 60;
60 |
61 | /**
62 | * --------------------------------------------------------------------------
63 | * Reserved Characters
64 | * --------------------------------------------------------------------------
65 | *
66 | * A string of reserved characters that will not be allowed in keys or tags.
67 | * Strings that violate this restriction will cause handlers to throw.
68 | * Default: {}()/\@:
69 | *
70 | * NOTE: The default set is required for PSR-6 compliance.
71 | */
72 | public string $reservedCharacters = '{}()/\@:';
73 |
74 | /**
75 | * --------------------------------------------------------------------------
76 | * File settings
77 | * --------------------------------------------------------------------------
78 | *
79 | * Your file storage preferences can be specified below, if you are using
80 | * the File driver.
81 | *
82 | * @var array{storePath?: string, mode?: int}
83 | */
84 | public array $file = [
85 | 'storePath' => WRITEPATH . 'cache/',
86 | 'mode' => 0640,
87 | ];
88 |
89 | /**
90 | * -------------------------------------------------------------------------
91 | * Memcached settings
92 | * -------------------------------------------------------------------------
93 | *
94 | * Your Memcached servers can be specified below, if you are using
95 | * the Memcached drivers.
96 | *
97 | * @see https://codeigniter.com/user_guide/libraries/caching.html#memcached
98 | *
99 | * @var array{host?: string, port?: int, weight?: int, raw?: bool}
100 | */
101 | public array $memcached = [
102 | 'host' => '127.0.0.1',
103 | 'port' => 11211,
104 | 'weight' => 1,
105 | 'raw' => false,
106 | ];
107 |
108 | /**
109 | * -------------------------------------------------------------------------
110 | * Redis settings
111 | * -------------------------------------------------------------------------
112 | *
113 | * Your Redis server can be specified below, if you are using
114 | * the Redis or Predis drivers.
115 | *
116 | * @var array{
117 | * host?: string,
118 | * password?: string|null,
119 | * port?: int,
120 | * timeout?: int,
121 | * async?: bool,
122 | * persistent?: bool,
123 | * database?: int
124 | * }
125 | */
126 | public array $redis = [
127 | 'host' => '127.0.0.1',
128 | 'password' => null,
129 | 'port' => 6379,
130 | 'timeout' => 0,
131 | 'async' => false, // specific to Predis and ignored by the native Redis extension
132 | 'persistent' => false,
133 | 'database' => 0,
134 | ];
135 |
136 | /**
137 | * --------------------------------------------------------------------------
138 | * Available Cache Handlers
139 | * --------------------------------------------------------------------------
140 | *
141 | * This is an array of cache engine alias' and class names. Only engines
142 | * that are listed here are allowed to be used.
143 | *
144 | * @var array<string, class-string<CacheInterface>>
145 | */
146 | public array $validHandlers = [
147 | 'apcu' => ApcuHandler::class,
148 | 'dummy' => DummyHandler::class,
149 | 'file' => FileHandler::class,
150 | 'memcached' => MemcachedHandler::class,
151 | 'predis' => PredisHandler::class,
152 | 'redis' => RedisHandler::class,
153 | 'wincache' => WincacheHandler::class,
154 | ];
155 |
156 | /**
157 | * --------------------------------------------------------------------------
158 | * Web Page Caching: Cache Include Query String
159 | * --------------------------------------------------------------------------
160 | *
161 | * Whether to take the URL query string into consideration when generating
162 | * output cache files. Valid options are:
163 | *
164 | * false = Disabled
165 | * true = Enabled, take all query parameters into account.
166 | * Please be aware that this may result in numerous cache
167 | * files generated for the same page over and over again.
168 | * ['q'] = Enabled, but only take into account the specified list
169 | * of query parameters.
170 | *
171 | * @var bool|list<string>
172 | */
173 | public $cacheQueryString = false;
174 |
175 | /**
176 | * --------------------------------------------------------------------------
177 | * Web Page Caching: Cache Status Codes
178 | * --------------------------------------------------------------------------
179 | *
180 | * HTTP status codes that are allowed to be cached. Only responses with
181 | * these status codes will be cached by the PageCache filter.
182 | *
183 | * Default: [] - Cache all status codes (backward compatible)
184 | *
185 | * Recommended: [200] - Only cache successful responses
186 | *
187 | * You can also use status codes like:
188 | * [200, 404, 410] - Cache successful responses and specific error codes
189 | * [200, 201, 202, 203, 204] - All 2xx successful responses
190 | *
191 | * WARNING: Using [] may cache temporary error pages (404, 500, etc).
192 | * Consider restricting to [200] for production applications to avoid
193 | * caching errors that should be temporary.
194 | *
195 | * @var list<int>
196 | */
197 | public array $cacheStatusCodes = [];
198 | }