Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce custom cache client support. #93

Merged
merged 8 commits into from
Oct 15, 2023

Conversation

fr33r
Copy link
Contributor

@fr33r fr33r commented Oct 17, 2022

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").

Planned Follow Ups

  • Explore the ability to disable caching completely.
  • Explore introducing options that automatically convert Redis and Memcache clients to UnitCacheClient.

Suggested Version

v4.0.0-beta.6

Example Usage

db := // ... database ...
cc := // ... cache client such as Redis or Memcache ...

opts = []unit.Option{
  unit.DB(db),
  unit.WithCacheClient(cc), // 🎉
}
u, err := unit.New(opts...)

@codecov
Copy link

codecov bot commented Oct 17, 2022

Codecov Report

All modified lines are covered by tests ✅

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%) ⬆️

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%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fr33r fr33r mentioned this pull request Oct 12, 2023
@fr33r fr33r marked this pull request as ready for review October 14, 2023 20:37
@fr33r fr33r self-assigned this Oct 15, 2023
@fr33r fr33r merged commit b1e142d into master Oct 15, 2023
12 checks passed
@fr33r fr33r deleted the freer/support-extendable-caching branch October 15, 2023 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant