Cache.php 6.1 KB

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