mirror of
https://github.com/twitter/the-algorithm.git
synced 2024-06-14 07:08:53 +02:00
![twitter-team](/assets/img/avatar_default.png)
Please note we have force-pushed a new initial commit in order to remove some publicly-available Twitter user information. Note that this process may be required in the future.
27 lines
989 B
Scala
27 lines
989 B
Scala
package com.twitter.follow_recommendations.common.candidate_sources.base
|
|
|
|
import com.twitter.escherbird.util.stitchcache.StitchCache
|
|
import com.twitter.finagle.stats.StatsReceiver
|
|
import com.twitter.product_mixer.core.functional_component.candidate_source.CandidateSource
|
|
import com.twitter.product_mixer.core.model.common.identifier.CandidateSourceIdentifier
|
|
import com.twitter.stitch.Stitch
|
|
import com.twitter.util.Duration
|
|
|
|
class CachedCandidateSource[K <: Object, V <: Object](
|
|
candidateSource: CandidateSource[K, V],
|
|
maxCacheSize: Int,
|
|
cacheTTL: Duration,
|
|
statsReceiver: StatsReceiver,
|
|
override val identifier: CandidateSourceIdentifier)
|
|
extends CandidateSource[K, V] {
|
|
|
|
private val cache = StitchCache[K, Seq[V]](
|
|
maxCacheSize = maxCacheSize,
|
|
ttl = cacheTTL,
|
|
statsReceiver = statsReceiver.scope(identifier.name, "cache"),
|
|
underlyingCall = (k: K) => candidateSource(k)
|
|
)
|
|
|
|
override def apply(target: K): Stitch[Seq[V]] = cache.readThrough(target)
|
|
}
|