Skip to content

Commit

Permalink
Add cache policy contract
Browse files Browse the repository at this point in the history
See issue: #17
  • Loading branch information
wax911 committed Jul 16, 2020
1 parent bee69ed commit 101c618
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2020 AniTrend
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package co.anitrend.data.cache.repository.contract

import org.threeten.bp.Instant
import org.threeten.bp.temporal.TemporalAmount

internal interface CacheStorePolicy {

/**
* Checks if the given [entityId] has been requested before a certain time [instant]
*/
suspend fun isRequestBefore(entityId: Long, instant: Instant): Boolean

/**
* Checks if the given [entityId] has expired using a [threshold]
*
* @see isRequestBefore
*/
suspend fun isRequestExpired(entityId: Long, threshold: TemporalAmount): Boolean

/**
* Checks if the given [entityId] has been requested before, regardless of when
*/
suspend fun hasBeenRequested(entityId: Long): Boolean

/**
* Check if a resource with a given [entityId] is permitted to refresh
*/
suspend fun shouldRefresh(
entityId: Long,
expiresAfter: Instant
): Boolean
}

0 comments on commit 101c618

Please sign in to comment.