> ./Makefile cacher
> ./cacher --help
usage: cacher [<flags>]
In-memory Redis-like cache.
Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
-i, --interface="http" Either http or telnet interface enable.
-a, --server=127.0.0.1 Server address.
-p, --port="1323" Server port.
--auth_token=AUTH_TOKEN Bearer Authentication Token.
-t, --cache_type="mutex-map" Select cache implementation.
--cdb Enable or disable save on disk using CDB.
--cdb_period=60 Period in seconds of dumping data to CDB.
--appendonly Enable or disable Append-only file.
--version Show application version.
There are two binary files "cacher" and "cacher_cli" at the root of git repo. Those are pre-compiled binaries of Cacher app and Cacher CLI can can be used be for quick launch apps w/o building them.
> ./cacher -t sync-map --auth_token 0123456789
> ./cacher -t sync-map -i telnet -p 5555
> ./Makefile test
> ./Makefile bench
> ./Makefile cacher_cli
> ./cacher_cli --help
usage: cacher-cli [<flags>] <command> [<args> ...]
CLI for Cacher application.
Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
--version Show application version.
Commands:
help [<command>...]
Show help.
telnet [<host>] [<port>]
Run Telnet client and connect with Telnet Cacher server
http --auth_token=AUTH_TOKEN [<flags>] <command> [<key>] [<value>] [<ttl>]
Use http client to send commands to Cacher.
> ./cacher -t sync-map --auth_token 0123456789
There are two thread-safe in-memory cache implementations supported by Cacher. First of "mutex-map" that uses regular Map data structure in pair with Mutexes to prevent concurrent writes. The second implementation is "sync-map" that uses Map from "sync" package - https://golang.org/src/sync/map.go. To switch between types could be used CL flag:
-t, --cache_type="mutex-map" Select cache implementation.
Cacher persistance implemented using Redis similar approach. There two options how persistance can be provided.
CDB is implemented by snapshoting in-memory cache to disk at specified intervals. By default CDB is enabled with interval 60 secs. Managing CDB and dumping interval could be changed using cli flags. In case if CDB is enabled and interval is 0 then every single Write/Delete Cacher operation will be immediately saved to CDB. In case if CDB is enabled and interval is greater than 0 then Batch Write to disk will be performed. CDB is using LevelDB as key-value disk storage.
In order to disable dumping data to disk could be used the following command:
> ./cacher -i telnet -p 5555 --no-cdb
AOF works using transaction log where every SET and DELETE operations will be appended to file. It should help to restore operations that were initiated but never finished. For example after killing process with 'kill -9'. Situations like CTRL+C handled separatelly by catching this signal and hence CDB batch operation has to finish dumping before exit. Command to disable AOF:
> ./cacher -i telnet -p 5555 --no-appendonly
Both modes could work together to provide higher durability. If both modes are enabled then restore from CDB processed and after that restore from AOF. AOF will restore only commands missed by CDB. In case if only AOF enabled then a full AOF log will be restored to in-memory DB.
In addition to AOF the Cacher uses own log file for tracking actions and errors. It located at './log/cacher.log'
Request for value of 'test' key
> ./cacher_cli http get test --auth_token 00000
Set array value
> ./cacher_cli http set test_array [9,2] --auth_token 00000
Set string value
> ./cacher_cli http set test_string \"string\" --auth_token 00000
Telnet client works as Standard telnet client in interactive mode. Run client
> ./cacher_cli telnet
> set test [1,2] 30
> keys
> get test
curl \
-X POST \
http://localhost:1323/ \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer 0123456789' \
-d '{"key":"test_string","value":"test_value", "ttl": 30}'
curl \
-X POST \
http://localhost:1323/ \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer 0123456789' \
-d '{"key":"test_array","value":["one","two","three"]}'
curl \
-X POST \
http://localhost:1323/ \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer 0123456789' \
-d '{"key":"test_map","value":{"test":1}}'
curl http://localhost:1323/keys -H 'Authorization: Bearer 0123456789'
> telnet localhost 5555
Note: whitespace is used as params separator
> set test_string test_value
> set test_array [1,2,3] 50
> set test_map {"test":1} 3600
> keys