1 module hunt.cache.CacheOptions; 2 3 import hunt.cache.Defined; 4 import hunt.redis.RedisPoolOptions; 5 6 import std.format; 7 import std.range; 8 9 enum string ADAPTER_MEMORY = "memory"; 10 enum string ADAPTER_MEMCACHE = "memcache"; 11 enum string ADAPTER_REDIS = "redis"; 12 enum string ADAPTER_ROCKSDB = "rocksdb"; 13 14 /** 15 * 16 */ 17 class CacheOptions { 18 19 string adapter = ADAPTER_MEMORY; 20 string prefix = ""; 21 22 bool isRedisClusterEnabled = false; 23 24 bool useSecondLevelCache = false; 25 uint maxEntriesLocalHeap = 10000; 26 bool eternal = false; 27 uint timeToIdleSeconds = 3600; 28 uint timeToLiveSeconds = 10; 29 bool overflowToDisk = true; 30 bool diskPersistent = true; 31 uint diskExpiryThreadIntervalSeconds = 120; 32 uint maxEntriesLocalDisk = 10000; 33 34 this() { 35 redisPool = new RedisPoolOptions(); 36 } 37 38 RedisClusterConfig redisCluster; 39 RedisPoolOptions redisPool; 40 MemcacheConf memcache; 41 RocksdbConf rocksdb; 42 43 struct MemoryConf { 44 long size = 65535; 45 bool persisted = false; // dependency RocksDB conf 46 } 47 48 struct MemcacheConf { 49 string host = "127.0.0.1"; 50 ushort port = 11211; 51 uint timeout = 0; 52 53 string toString() { 54 return format("memecache://%s:%d/?timeout=%d", host, port, timeout); 55 } 56 } 57 58 struct RocksdbConf { 59 string file = "storages/cache.db"; 60 } 61 62 override string toString() { 63 if (adapter == ADAPTER_MEMORY) { 64 return format("adapter: %s, prefix: %s, Redis: {%s}", adapter, 65 prefix, redisPool.toString()); 66 } else if (adapter == ADAPTER_MEMCACHE) { 67 return format("adapter: %s, prefix: %s, Memcache: {%s}", adapter, 68 prefix, memcache.toString()); 69 } else { 70 return format("adapter: %s, prefix: %s", adapter, prefix); 71 } 72 } 73 }