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

scalacache: Create multiple cache regions #658

Open
nikoplusx opened this issue Mar 3, 2022 · 0 comments
Open

scalacache: Create multiple cache regions #658

nikoplusx opened this issue Mar 3, 2022 · 0 comments

Comments

@nikoplusx
Copy link

I have a repository class and I want to create 2 different cache regions for 2 different types of queries. Let's say that we have typea andtypeab. I am using scalacache with caffeine as the underlying implementation. Based on the docs, one has to configure it like so:

lazy val underlyingTypeACaffeineCache = Caffeine
    .newBuilder()
    .maximumSize(CACHE_SIZE)
    .build[String, Entry[List[Event]]]
  implicit lazy val customisedTypeACaffeineCache: CaffeineCache[List[Event]] =
    CaffeineCache(underlyingTypeACaffeineCache)

and you should call it like

sync.caching("key")(ttl=None){...}

This sync interface picks up the implicit and caches the values appropriately. What happens when you want to have different regions though under the same roof/class. For example

lazy val underlyingTypeACaffeineCache = Caffeine
    .newBuilder()
    .maximumSize(CACHE_SIZE)
    .build[String, Entry[List[Event]]]
  implicit lazy val customisedTypeACaffeineCache: CaffeineCache[List[Event]] =
    CaffeineCache(underlyingTypeACaffeineCache)

lazy val underlyingTypeBCaffeineCache = Caffeine
    .newBuilder()
    .maximumSize(CACHE_SIZE)
    .build[String, Entry[List[Event]]]
  implicit lazy val customisedTypeBCaffeineCache: CaffeineCache[List[String]] =
    CaffeineCache(underlyingTypeBCaffeineCache)

then the sync interface does not work since it gets confused as to which implicit to use. How do you overcome this?

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

No branches or pull requests

1 participant