Skip to content
Cache library for D. Support memory、redis、memcached backend.
D
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
source/hunt/cache
.gitignore Test redis Jul 25, 2019
.travis.yml
README.md Change README.md description. Jul 4, 2019
dub.json

README.md

Build Status

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

import hunt.cache;

import std.stdio;

void main()
{
    auto cache = CacheFectory.create();

    // define key
    string key = "my_cache_key";
    // set cache
    cache.set(key, "My cache value.");

    // get cache
    string value = cache.get(key);

    writeln(value);
}

Sample code for struct & class

import hunt.cache;

import std.stdio;

struct User
{
    string name;
    int age;
}

void main()
{
    auto cache = CacheFectory.create();

    // define key
    string key = "user_info";

    User user;
    user.name = "zoujiaqing";
    user.age = 99;

    // set cache
    cache.set(key, user);

    // get cache
    User userinfo = cache.get!User(key);

    writeln(userinfo.name);
}

How to use Redis adapter?

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 = CacheFectory.create(option);

    // code for set / get ..
}
You can’t perform that action at this time.