Skip to content

cachingF: conditionally cache based on function evaluation result type #194

Open
@sebarys

Description

@sebarys

Hello,

I want use cache to store token evaluations for given client credentials:

def fetchToken(clientCredentials: ClientCredentials): Future[Either[MyError, Token]] = {
    import scala.concurrent.ExecutionContext.Implicits.global
    import scalacache.modes.scalaFuture._

    cachingF(clientCredentials)(ttl = Some(cacheConfig.cachingTime)) {
      defaultTokenRepository.fetchToken(clientCredentials)
    }

  }

I want to cache only Future(Right()) results.
Future.failed an Future(Left()) result shouldn't be cached and evaluated in next function call again.
Is there any way to provide logic which result of function evaluation should be stored in the cache?

Thank you for any suggestions!

Regards,
Sebastian

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions