assignment.AssignmentFilter.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of experiment-jvm-server Show documentation
Show all versions of experiment-jvm-server Show documentation
Amplitude Experiment server-side SDK for JVM (Java, Kotlin)
package com.amplitude.experiment.assignment
import com.amplitude.experiment.util.Cache
internal interface AssignmentFilter {
fun shouldTrack(assignment: Assignment): Boolean
}
internal class InMemoryAssignmentFilter(size: Int, ttlMillis: Long = DAY_MILLIS) : AssignmentFilter {
// Cache of canonical assignment to the last sent timestamp.
private val cache = Cache(size, ttlMillis)
override fun shouldTrack(assignment: Assignment): Boolean {
val canonicalAssignment = assignment.canonicalize()
val track = cache[canonicalAssignment] == null
if (track) {
cache[canonicalAssignment] = Unit
}
return track
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy