Skip to content

About the api design #903

Answered by ben-manes
He-Pin asked this question in Q&A
Apr 7, 2023 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Why there is a put but not a remove on the Cache? and I always want to use a val cachedValue = cache.remove(key) like thing.

A cache removal is usually called an invalidation so we have Cache.invalidate(key). This is a void method because best practice is to not rely or assume anything about the current contents of the cache and treat it as a transparent, transient storage layer. That makes the Cache interface opinionated. However, options or best practices shouldn't stop a developer from solving their problems, so we have the asMap() view for the familiar Collections interfaces. A Map is typically a passive data structure, e.g. it isn't changing underneath you, whereas a Cache is an ac…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@He-Pin
Comment options

Answer selected by ben-manes
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants