work icon indicating copy to clipboard operation
work copied to clipboard

Introduce support for caching.

Open fr33r opened this issue 4 years ago • 0 comments

Description

Takes on #24!

Rationale

This feature unlocks the ability to prevent loading the same object (entity) from the applications data store. At the same call sites as #Register, consumers of this package can now check whether the entity / entities being retrieved have already been retrieved and not been acted upon (also referred to as "dirty").

For smaller applications, this ability may seem unnecessary, but as a codebase becomes larger and more complex, there typically arises a need to ensure particular objects are not loaded multiple times unnecessarily.

Callouts

I initially hesitated on these changes, as in order to maintain the cache properly, the work unit needs to know the ID of each entity it is tracking. To accomplish this, it requires making interface changes - essentially replacing interface{} with Entity.

I felt that this feature was important enough to make the switch, and consumers of this library likely already have an identifier defined on the objects they were tracking with work units. Adding a single method ( #ID() ) should hopefully be a small add for outsized benefit.

Disagree? Let me know - let's get a discussion started 😄 !

Suggested Version

v4.0.0-beta.3

fr33r avatar Nov 15 '21 06:11 fr33r