All Downloads are FREE. Search and download functionalities are using the official Maven repository.

assignment.AssignmentFilter.kt Maven / Gradle / Ivy

There is a newer version: 1.6.1
Show newest version
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