Hunt Cache
Universal cache library for D programming language.
Support backend
- memory
- redis
- libmemcached
Versions
- WITH_HUNT_CACHE
- WITH_HUNT_REDIS
- WITH_HUNT_MEMCACHE
- WITH_HUNT_ROCKSDB
Tips
Default support memory and redis drivers.
Sample code for Memory adapter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| import hunt.cache;
import std.stdio;
void main() { auto cache = CacheFactory.create();
string key = "my_cache_key"; cache.set(key, "My cache value.");
string value = cache.get(key);
writeln(value); }
|
Sample code for struct & class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| import hunt.cache;
import std.stdio;
struct User { string name; int age; }
void main() { auto cache = CacheFactory.create();
string key = "user_info";
User user; user.name = "zoujiaqing"; user.age = 99;
cache.set(key, user);
User userinfo = cache.get!User(key);
writeln(userinfo.name); }
|
How to use Redis adapter?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| import hunt.cache;
import std.stdio;
void main() { CacheOption option; option.adapter = "redis"; option.redis.host = "127.0.0.1"; option.redis.port = 6379;
auto cache = CacheFactory.create(option);
}
|