In-memory cache server with partial data persistence and clustering
Yet another Redis-like in-memory cache server written in Go.
Could be used for saving sessions, counters and other types of information with limited lifetime and very fast access. GCache supports easy scaling for data retrieval operations with master-slave replication.
For building cache server Go 1.8+ is required.
go get github.com/dgtony/gcache
After installation GCache could be started with defined configuration:
gcache -c <path_to_config_file.toml>
GCache currently supports following basic operations:
Operation SET performed on existing key will update its value and TTL.
There are two variations of KEYS command: using plain version will return all keys stored in cache, while adding mask parameter enforce server to return only matching keys. Glob pattern matching rules used to create mask, similar to Redis.
Note: as usual, KEYS could be a very expensive kind of operation, use it with care!
Internal elements of complex data types, such as arrays and dictionaries, could be efficiently accessed with additional methods:
Note: subindexing in value array starts from 1, element index 0 will return entire array!
In order to add some persistence data stored in cache memory could be periodically dumped in file. As the node starts it may use such snapshot file to restore data from the previous session. Please mind, that after cache re-establishment all outdated keys will be removed.
Dumping and restoring options could be set in node’s configuration file.
Note: slave nodes (see below) do not restore its cache from file, but only from the master-node.
Each cache node could be started in one of the following modes:
Standalone node works as a single server and makes no communication with other nodes.
For the purposes of scaling data retrieval process GCache could be horizontally sharded in a cluster. Cluster consists of a single master-node and several slave-nodes. Data modifying operations, such as GET/REMOVE are allowed only on master node, while values could be retrieved from slaves, as well. System is based on eventual consistency model, where slaves periodically update its cache from master node.
One can adjust data inconsistency window with dump_update_period
parameter in node configuration file.
GCache provides REST API as a standard server access interface. Swagger-powered API specification could be found in file docs/rest_api.html
.
At the moment the only existing native client is gclient – thin library written in Go. More information about library and usage examples could be found in the project repository.
Results of benchmarking GCache via REST API could be found here.
Project just started, and there are a lot of things to be done. Among others:
Any help is welcome :)