Cache.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. * Key Prefix
  35. * --------------------------------------------------------------------------
  36. *
  37. * This string is added to all cache item names to help avoid collisions
  38. * if you run multiple applications with the same cache engine.
  39. */
  40. public string $prefix = '';
  41. /**
  42. * --------------------------------------------------------------------------
  43. * Default TTL
  44. * --------------------------------------------------------------------------
  45. *
  46. * The default number of seconds to save items when none is specified.
  47. *
  48. * WARNING: This is not used by framework handlers where 60 seconds is
  49. * hard-coded, but may be useful to projects and modules. This will replace
  50. * the hard-coded value in a future release.
  51. */
  52. public int $ttl = 60;
  53. /**
  54. * --------------------------------------------------------------------------
  55. * Reserved Characters
  56. * --------------------------------------------------------------------------
  57. *
  58. * A string of reserved characters that will not be allowed in keys or tags.
  59. * Strings that violate this restriction will cause handlers to throw.
  60. * Default: {}()/\@:
  61. *
  62. * NOTE: The default set is required for PSR-6 compliance.
  63. */
  64. public string $reservedCharacters = '{}()/\@:';
  65. /**
  66. * --------------------------------------------------------------------------
  67. * File settings
  68. * --------------------------------------------------------------------------
  69. *
  70. * Your file storage preferences can be specified below, if you are using
  71. * the File driver.
  72. *
  73. * @var array<string, int|string|null>
  74. */
  75. public array $file = [
  76. 'storePath' => WRITEPATH . 'cache/',
  77. 'mode' => 0640,
  78. ];
  79. /**
  80. * -------------------------------------------------------------------------
  81. * Memcached settings
  82. * -------------------------------------------------------------------------
  83. *
  84. * Your Memcached servers can be specified below, if you are using
  85. * the Memcached drivers.
  86. *
  87. * @see https://codeigniter.com/user_guide/libraries/caching.html#memcached
  88. *
  89. * @var array<string, bool|int|string>
  90. */
  91. public array $memcached = [
  92. 'host' => '127.0.0.1',
  93. 'port' => 11211,
  94. 'weight' => 1,
  95. 'raw' => false,
  96. ];
  97. /**
  98. * -------------------------------------------------------------------------
  99. * Redis settings
  100. * -------------------------------------------------------------------------
  101. *
  102. * Your Redis server can be specified below, if you are using
  103. * the Redis or Predis drivers.
  104. *
  105. * @var array<string, int|string|null>
  106. */
  107. public array $redis = [
  108. 'host' => '127.0.0.1',
  109. 'password' => null,
  110. 'port' => 6379,
  111. 'timeout' => 0,
  112. 'database' => 0,
  113. ];
  114. /**
  115. * --------------------------------------------------------------------------
  116. * Available Cache Handlers
  117. * --------------------------------------------------------------------------
  118. *
  119. * This is an array of cache engine alias' and class names. Only engines
  120. * that are listed here are allowed to be used.
  121. *
  122. * @var array<string, class-string<CacheInterface>>
  123. */
  124. public array $validHandlers = [
  125. 'dummy' => DummyHandler::class,
  126. 'file' => FileHandler::class,
  127. 'memcached' => MemcachedHandler::class,
  128. 'predis' => PredisHandler::class,
  129. 'redis' => RedisHandler::class,
  130. 'wincache' => WincacheHandler::class,
  131. ];
  132. /**
  133. * --------------------------------------------------------------------------
  134. * Web Page Caching: Cache Include Query String
  135. * --------------------------------------------------------------------------
  136. *
  137. * Whether to take the URL query string into consideration when generating
  138. * output cache files. Valid options are:
  139. *
  140. * false = Disabled
  141. * true = Enabled, take all query parameters into account.
  142. * Please be aware that this may result in numerous cache
  143. * files generated for the same page over and over again.
  144. * ['q'] = Enabled, but only take into account the specified list
  145. * of query parameters.
  146. *
  147. * @var bool|list<string>
  148. */
  149. public $cacheQueryString = false;
  150. }