Make the readme more clear
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Tyler 2019-10-05 23:46:30 -04:00
parent 3e6d1a1cc2
commit 68bbfbacd0

View File

@ -3,9 +3,9 @@ CacheInterface
[![Build Status](https://drone.meow.tf/api/badges/tyler/cacheinterface/status.svg)](https://drone.meow.tf/tyler/cacheinterface)
An experimental interface to use different caches interchangeably via URIs
An experimental interface to use different caches interchangeably via URIs. The goal for this library is to simplify using a caching layer for use with different services, enabling easy swapping of backends without the hassle of configuration.
Example Cache URIs:
To achieve this, we use unique "uris" for each driver, giving us a single string to configure the settings, much like database servers and other software.
```
redis://server:port?db=0&password=test
@ -14,17 +14,51 @@ memory://
lru://?size=128
```
Code
Cache Types
-----------
LRU
Implemented using [github.com/hashicorp/golang-lru](https://github.com/hashicorp/golang-lru), this driver provides an in-memory lru cache implementation. Items in this cache will be evicted on an as-needed basis, with the most frequently used items staying in memory longer.
Memory
Implemented using [github.com/patrickmn/go-cache](https://github.com/patrickmn/go-cache), this driver provides an in-memory object cache. This driver specifically supports non-serialized storing of objects when using Get(key, dstPointer)
Memcache
Implemented using [github.com/bradfitz/gomemcache](https://github.com/bradfitz/gomemcache/memcache), this driver provides a Memcache connector for the Memcached protocol and compatible servers.
Redis
Implemented using [github.com/hoisie/redis](https://github.com/hoisie/redis), this driver provides a Redis connector for the ever popular Redis key-value store.
Serialization
-------------
When the driver requires it, values are almost always serialized into `[]byte`. The library can automatically handle this as long as the structures are supported by msgpack. Future plans may include other serialization methods or customized serialization.
The exception to the above is for raw `[]byte` values and strings (stored as a `[]byte`), as they can be easily converted.
API
----
The CacheInterface interface has all methods. All clients will implement this on a best-effort basis.
The CacheInterface interface has all methods. All drivers will implement this on a best-effort basis.
```go
type CacheInterface interface {
Has(key string) bool
Get(key string) ([]byte, error)
Get(key string, dst ...interface{}) ([]byte, error)
Set(key string, val interface{}, ttl time.Duration) (err error)
Del(key string) error
}
```
Note: Set will automatically attempt to store byte arrays and strings directly, and encode the rest with JSON.
In addition to this, cache drivers can be used without the `cacheinterface.New` method by using the `New<Driver>Cache` method and providing the necessary parameters.
Code & Testing
--------------
As many test methods as we can add have been implemented, with the exception being those the CI service (Drone) cannot support (Memcache, Redis) due to limitations using extra services.
All code should have tests to verify there isn't anything broken with a new commit.