Skip to content

Add GetPossiblyExpired()#47

Open
Freeaqingme wants to merge 1 commit intopatrickmn:masterfrom
Freeaqingme:master
Open

Add GetPossiblyExpired()#47
Freeaqingme wants to merge 1 commit intopatrickmn:masterfrom
Freeaqingme:master

Conversation

@Freeaqingme
Copy link
Copy Markdown

In some situations it's okay to receive stale data. In fact, I have an application that depends on it. I wasn't able to access that data out of the box, and as such I added this function.

@patrickmn
Copy link
Copy Markdown
Owner

I'm not sold on this one, but not necessarily against it. Do you have an example of how this would be useful?

@rahulraheja
Copy link
Copy Markdown

rahulraheja commented Apr 30, 2017

A use case I have is I am reading data from a database and caching it for x minutes. But if the database connection is lost for some reason, i'd love to keep reading stale data from the cache till the db comes back up online, rather than causing my application to return no data.

With Freeaqingme’s approach, the pattern would be GetFromCache, if expired GetFromDb, if error or could not make connection, GetExpiredData if present.

As an implementation option, one can also consider with the GetFromCache call, you could return the data and indicate in some way (can think of a couple) whether the data is stale, in which case one could replace it.

@Freeaqingme
Copy link
Copy Markdown
Author

I started off with something similar as @rahulraheja described. However, in my case, the cached data is certain not to change once it's been persisted. Although it is possible for something to be no longer useful. E.g., when a user is assigned to shard X, that will never change. But it's possible for that user to cancel his product, and then you'd want the item to eventually disappear from cache. So, if the item still appears in cache, I'm fine with using it. Even when it has expired.

I implemented that here: https://github.com/Freeaqingme/influxdb-relay/blob/master/relay/shardAssignmentStore.go#L69

(it's been a while since I implemented it. There may have been an ulterior grand design behind this, but reading the code I can't really figure out what that should have been...)

@rahulraheja
Copy link
Copy Markdown

@patrickmn Does this satisfy your question on use cases? I would love to get this feature in (to support graceful degradation) either with @Freeaqingme implementation recommendation or if you have any other recommendation to achieve the same effect.

@rahulraheja
Copy link
Copy Markdown

Another possible implementation
#53

@pablodz
Copy link
Copy Markdown

pablodz commented Jan 3, 2024

Found this fork: https://github.com/arp242/zcache

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.

5 participants