Introduce custom cache client support.
Description
Introduces support for consumers of work to provide their own cache clients in the event they wish not to use the default in-memory caching. For example, users may provide clients for Redis or Memcache instead if they desire some distributed caching options.
Rationale
Depending on the use cases consumers of this library may be dealing with very large sets of data and performing large scale modifications over that data. Using an in-memory caching solution only is applicable in scenarios where the limits of how many entities to be cached is well defined and is small enough to not overwhelm the system. In all other scenarios, distributed caching is a much safer alternative.
Callouts
In order to achieve this, context.Context had to be introduced on all unit operations. This is because all of the operations would result in issuing remote calls to the cache (using the provided clients), as all operations besides Register result in deleting the corresponding entity from the cache (since it would then be classified as "dirty").
TODO
- Add ability to disable caching.
- Add options that automatically convert Redis and Memcache clients to
UnitCacheClient.
Suggested Version
v4.0.0-beta.6
Example Usage
TBD
Codecov Report
All modified lines are covered by tests :white_check_mark:
Comparison is base (
d81ce30) 98.71% compared to head (9976548) 98.72%.
Additional details and impacted files
@@ Coverage Diff @@
## master #93 +/- ##
=======================================
Coverage 98.71% 98.72%
=======================================
Files 14 14
Lines 1399 1407 +8
=======================================
+ Hits 1381 1389 +8
Misses 14 14
Partials 4 4
| Flag | Coverage Δ | |
|---|---|---|
| v3 | 98.71% <ø> (ø) |
|
| v4 | 98.72% <100.00%> (+0.01%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Files | Coverage Δ | |
|---|---|---|
| v4/unit.go | 100.00% <100.00%> (ø) |
|
| v4/unit_cache.go | 100.00% <100.00%> (ø) |
|
| v4/unit_options.go | 99.58% <100.00%> (+<0.01%) |
:arrow_up: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.