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

💡 [patch] WriteThroughCache: cautionary JSDoc #95

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/lib/WriteThroughCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,31 @@ import { LocalCache } from './LocalCache';


/**
Copy link
Contributor Author

@ronjouch ronjouch Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder that cachette is public, no disclosing world domination plans in PR comments.

* Write-through cache, using Redis and a local LRU cache.
* Write-through cache, using Redis and a local LRU cache with aligned TTLs.
*
* **WARNING** if using this in a distributed app where cache consistency matters!
* Consider this case of an app with several servers/instances using WriteThroughCache:
* 1. Instance I1 sets key/value foo: bar (both local & redis)
* 2. Instance I2 gets value foo, populating its local cache with "bar"
* ----- At that moment, LocalCaches of I1 & I2 are aligned, foo: bar
* 3. Instance I1 deletes key foo (both local & redis)
* ----- At that moment, LocalCaches of I1 & I2 are *mis*aligned about foo!
* - I1 has nothing
* - I2 has "bar"
*
* -> This is fixable, e.g. using Redis pub/sub, to let clients subscribe to
* set/del events, and react with an eviction from their LocalCache.
* In the context we cachette maintainers got bitten by this, it made sense
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? This sounds funny when I read it

Suggested change
* In the context we cachette maintainers got bitten by this, it made sense
* We cachette maintainers got bitten by this, and it made sense

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 was weird, I tend to over-omit some liaison words. Fixed in 5280a24.

* to simply abandon usage of WriteThroughCache, and switch the app with high
* consistency expectations from a WriteThroughCache to a RedisCache:
* +++: simpler, more consistent
* ---: a tolerable increase in Redis usage (CPU, network, latency)
*
* So, pub/sub remains unimplemented, but it would be a reasonable addition.
* API design consideration: set/dels maybe shouldn't *always* cause Redis
* publish (said differently, maybe not *all* set/dels should cause a
* LocalCache eviction, to limit pub/sub traffic explosion? Maybe, or maybe
* "pub/sub traffic explosion" is a non-concern? To be evaluated :)
*/
export class WriteThroughCache extends CacheInstance {

Expand Down
Loading