cache.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /* 缓存设置。Cache settings. */
  3. $config->cache = new stdclass();
  4. $config->cache->enable = false; // 是否开启缓存。Enable cache or not.
  5. $config->cache->driver = 'apcu'; // 缓存驱动。 The driver of cache. Can be file|yac|apcu|redis.
  6. $config->cache->scope = ''; // 缓存服务范围。The scope of cache. Can be private|shared.
  7. $config->cache->namespace = ''; // 缓存命名空间。The namespace of cache.
  8. $config->cache->lifetime = 0; // 缓存生存时间,默认永不过期。The lifetime of cache. Default is no expiration.
  9. $config->cache->dao = new stdClass();
  10. $config->cache->dao->enable = true; // 是否开启 DAO 缓存。Enable DAO cache or not.
  11. $config->cache->dao->lifetime = 604800; // DAO 缓存生存时间,默认为 7 天。The lifetime of DAO cache. Default is 7 days.
  12. $config->cache->client = new stdClass();
  13. $config->cache->client->enable = false; // 是否开启客户端缓存。Enable client cache or not.
  14. // Format : $config->cache->raw[TABLE_NAME] = 'KEY_FIELD';
  15. // The TABLE_NAME is the name of the table in the database.
  16. // The KEY_FIELD is the field of the table which is used to generate the key of the cache. It must be unique in the table.
  17. $config->cache->raw = [];
  18. $config->cache->raw[TABLE_ACL] = 'id';
  19. $config->cache->raw[TABLE_CONFIG] = 'id';
  20. $config->cache->raw[TABLE_BUILD] = 'id';
  21. $config->cache->raw[TABLE_MODULE] = 'id';
  22. $config->cache->raw[TABLE_PRODUCT] = 'id';
  23. $config->cache->raw[TABLE_PROJECT] = 'id';
  24. $config->cache->raw[TABLE_RELEASE] = 'id';
  25. $config->cache->raw[TABLE_STAKEHOLDER] = 'id';
  26. $config->cache->raw[TABLE_TEAM] = 'id';
  27. $config->cache->raw[TABLE_USER] = 'account';
  28. $config->cache->res = [];
  29. $config->cache->res[TABLE_MODULE][] = ['name' => 'CACHE_MODULE_TREE', 'fields' => ['type', 'root', 'branch']];
  30. $config->cache->res[TABLE_PROJECT][] = ['name' => 'CACHE_PROJECT_TYPE'];
  31. $config->cache->keys = [];
  32. foreach($config->cache->res as $table => $caches)
  33. {
  34. foreach($caches as $cache)
  35. {
  36. $cache = (object)$cache;
  37. $cache->table = $table;
  38. $config->cache->keys[$cache->name] = $cache;
  39. define($cache->name, $cache->name);
  40. }
  41. }
  42. $config->redis = new stdClass();
  43. $config->redis->host = '';
  44. $config->redis->port = '';
  45. $config->redis->username = '';
  46. $config->redis->password = '';
  47. $config->redis->database = 0;
  48. $config->redis->serializer = 'igbinary'; // php|igbinary
  49. /* 在镜像或渠成平台中运行时,从环境变量中加载缓存配置。Load cache settings from environment variables when running in container or Quickon. */
  50. if($config->inContainer || $config->inQuickon)
  51. {
  52. $config->cache->enable = getenv('ZT_CACHE_ENABLE') ?: false;
  53. $config->cache->driver = getenv('ZT_CACHE_DRIVER') ?: 'apcu';
  54. $config->cache->scope = getenv('ZT_CACHE_SCOPE') ?: '';
  55. $config->cache->namespace = getenv('ZT_CACHE_NAMESPACE') ?: '';
  56. $config->cache->lifetime = getenv('ZT_CACHE_LIFETIME') ?: 0;
  57. $config->redis->host = getenv('ZT_REDIS_HOST') ?: '';
  58. $config->redis->port = getenv('ZT_REDIS_PORT') ?: '';
  59. $config->redis->username = getenv('ZT_REDIS_USERNAME') ?: '';
  60. $config->redis->password = getenv('ZT_REDIS_PASSWORD') ?: '';
  61. $config->redis->database = getenv('ZT_REDIS_DATABASE') ?: 0;
  62. $config->redis->serializer = getenv('ZT_REDIS_SERIALIZER') ?: 'igbinary';
  63. }