-
Notifications
You must be signed in to change notification settings - Fork 120
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
Support polymorphic keys #565
Support polymorphic keys #565
Conversation
@@ -65,17 +60,17 @@ object CaffeineCache { | |||
|
|||
/** Create a new Caffeine cache. | |||
*/ | |||
def apply[F[_]: Sync: Clock, V](implicit config: CacheConfig): F[CaffeineCache[F, V]] = | |||
Sync[F].delay(Caffeine.newBuilder().build[String, Entry[V]]()).map(apply(_)) | |||
def apply[F[_]: Sync: Clock, K <: AnyRef, V]: F[CaffeineCache[F, K, V]] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like Caffeine requires the K and V to both extend Object
(from Java). This wasn't a problem in the past because we were always using String keys. Weirdly, this also only seems to be an issue on Scala 2.12 as it compiles fine for 2.13 and 3. I had to add <: AnyRef
just for 2.12, but I am not really sure of an alternative. @kubukoz Do you happen to have any thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an issue #603 to discuss this further. Merging this PR so we can continue on with other things in the meantime.
Thanks again @ronnnnnnnnnnnnn for putting this together and sorry it took so long to get around to merging. |
With regard to standardizing the key serialization by making it part of AbstractCache - didn't think it was really necessary so preferred to keep it cleaner and more consistent with value serialization which is left up to the various implementations. I did make some changes to the codec library to allow for simple usage by implementations also for keys, and added such usage to the Redis implementation.
However, If you think it might still be better to standardize it some more, maybe I can add another layer for that inheriting from AbstractCache or something.
Anyway, I hope this is alright. Let me know what you think.