Cache.php 7.1 KB

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