As shown in the title, DREAMEMO is a distributed cache with out-of-the-box, high-scalability, modular-design features.The groupcache implementation is referenced, and re-structured, specific module differentiation is as follows:
The main modules will be introduced in detail in the design module.
Quick Start
Install
Execute following command to install DREAMEMO:
Run with standalone mode
DREAMEMO provides a function dream.StandAlone used default configuration to help user to start in standalone mode swiftly. All you need to do is configure the source.Getter of the corresponding data source.
Here in the form of a map simulation data source database, and use PIANO HTTP framework as a front-end server instead of using other HTTP frameworks like Hertz, Gin, etc. You can start the server with go run . and then simply visit the URL to retrieve the key.
Run with cluster mode
DREAMEMO also provides a dream.Cluster function that runs in Cluster mode using the default configuration. All you need to do is configure the address of the corresponding cluster node and the data source.
Again, the database data source is simulated as map, and three cache nodes are configured at localhost:7246, localhost:7247 and localhost:7248, the frontend server is configured on port 8080. To retrieve the value of the key, run the following command and visit the URL:
Custom Assemble
dream.StandAlone and dream.Cluster functions configured by DREAMEMO were used earlier, here we’ll look at a more customized way of running the assembly.
Configure Engine
Here we configure the engine, util.ParseFlags is a utility method provided to parse flag arguments. We use app.WithHostAddr to configure the engine to listen to and app.WithThrift0 to use Thrift as the serialization protocol and register other nodes.
Configure cache eliminate strategy
Configure LFU
Configure cache group
We configure the cache group name with guidance.WithGroupName, configure Thrift as the serialization protocol with guidance.WithThrift1, be consistent with the engine, and configure the data source with source.Getter
The complete code is as follows:
Run and get the cache value with the following command:
Design
Eliminate strategy
In terms of cache elimination strategy, DREAMEMO supports LRU and LFU cache elimination algorithms, and users can choose and assemble them by themselves:
LRU
LFU
DREAMEMO also provides an interface for uses to extend other eliminate strategies. Just implement the interface and pass the object to memo.NewMemo as follows:
Serialization
DREAMEMO supports both Thrift and Protobuf serialization protocols.The default is Protobuf, and to use Thrift, you need to enable Thrift in both the configuration engine and the cache group:
Data Source
DREAMEMO provides a default configuration to use Redis as a data source:
DREAMEMO also provides an interface to configure more data sources of your own:
Consistent Hash
DREAMEMO, like groupcache, uses consistent hashing for distributed node selection, while also providing an interface to configure more policies.
TODO
DREAMEMO is still very young, and there are many changes that can be made to it. In the future, more node selection algorithms and quick configuration tools will be provided.
Summary
That’s all for this article. Hope this can help you. I would be appreciate if you could give DREAMEMO a star.
If you have any questions, please leave them in the comments or as issues. Thanks for reading.