This is an automated email from the ASF dual-hosted git repository. markusthoemmes pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push: new bd84ab5 Use cache invalidation policy based on access time. (#3146) bd84ab5 is described below commit bd84ab57c3dadcddcead1699bc016bdf01cd27e6 Author: James Dubee <jwdu...@us.ibm.com> AuthorDate: Mon Jan 8 10:15:43 2018 -0500 Use cache invalidation policy based on access time. (#3146) * Use cache invalidation policy based on access time * Allow multiple cache policies and do not create cache if caching is disabled - Add per-cache configration for eviction - Lazily instantiate cache - Prevents cache from being instantiate when fromCache is false --- .../MultipleReadersSingleWriterCache.scala | 35 +++++++++++++++++----- .../main/scala/whisk/core/entity/Identity.scala | 3 ++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/common/scala/src/main/scala/whisk/core/database/MultipleReadersSingleWriterCache.scala b/common/scala/src/main/scala/whisk/core/database/MultipleReadersSingleWriterCache.scala index 6fa76d2..5866355 100644 --- a/common/scala/src/main/scala/whisk/core/database/MultipleReadersSingleWriterCache.scala +++ b/common/scala/src/main/scala/whisk/core/database/MultipleReadersSingleWriterCache.scala @@ -91,12 +91,18 @@ private object MultipleReadersSingleWriterCache { trait CacheChangeNotification extends (CacheKey => Future[Unit]) +sealed trait EvictionPolicy + +case object AccessTime extends EvictionPolicy +case object WriteTime extends EvictionPolicy + trait MultipleReadersSingleWriterCache[W, Winfo] { import MultipleReadersSingleWriterCache._ import MultipleReadersSingleWriterCache.State._ /** Subclasses: Toggle this to enable/disable caching for your entity type. */ protected val cacheEnabled = true + protected val evictionPolicy: EvictionPolicy = AccessTime private object Entry { def apply(transid: TransactionId, state: State, value: Option[Future[W]]): Entry = { @@ -438,14 +444,27 @@ trait MultipleReadersSingleWriterCache[W, Winfo] { } /** This is the backing store. */ - private val cache: ConcurrentMapBackedCache[Entry] = new ConcurrentMapBackedCache( - Caffeine - .newBuilder() - .asInstanceOf[Caffeine[Any, Future[Entry]]] - .expireAfterWrite(5, TimeUnit.MINUTES) - .softValues() - .build() - .asMap()) + private lazy val cache: ConcurrentMapBackedCache[Entry] = evictionPolicy match { + case AccessTime => + new ConcurrentMapBackedCache( + Caffeine + .newBuilder() + .asInstanceOf[Caffeine[Any, Future[Entry]]] + .expireAfterAccess(5, TimeUnit.MINUTES) + .softValues() + .build() + .asMap()) + + case _ => + new ConcurrentMapBackedCache( + Caffeine + .newBuilder() + .asInstanceOf[Caffeine[Any, Future[Entry]]] + .expireAfterWrite(5, TimeUnit.MINUTES) + .softValues() + .build() + .asMap()) + } } /** diff --git a/common/scala/src/main/scala/whisk/core/entity/Identity.scala b/common/scala/src/main/scala/whisk/core/entity/Identity.scala index 358b60f..e1b2526 100644 --- a/common/scala/src/main/scala/whisk/core/entity/Identity.scala +++ b/common/scala/src/main/scala/whisk/core/entity/Identity.scala @@ -27,6 +27,7 @@ import whisk.common.TransactionId import whisk.core.database.MultipleReadersSingleWriterCache import whisk.core.database.NoDocumentException import whisk.core.database.StaleParameter +import whisk.core.database.WriteTime import whisk.core.entitlement.Privilege case class UserLimits(invocationsPerMinute: Option[Int] = None, @@ -50,6 +51,8 @@ object Identity extends MultipleReadersSingleWriterCache[Identity, DocInfo] with private val viewName = "subjects/identities" override val cacheEnabled = true + override val evictionPolicy = WriteTime + implicit val serdes = jsonFormat5(Identity.apply) /** -- To stop receiving notification emails like this one, please contact ['"commits@openwhisk.apache.org" <commits@openwhisk.apache.org>'].