Skip to content

Commit

Permalink
Allow resetting a subset
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecorry31 committed Mar 15, 2024
1 parent bbb37de commit 9996b93
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/main/kotlin/com/kylecorry/luna/cache/Hooks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,33 @@ class Hooks {
return memo.getOrPut(*values, value = value)
}

fun resetEffects(except: List<String> = emptyList()) {
/**
* Resets effects
* @param keys The keys to reset, if null all effects are reset
* @param except The keys to not reset
*/
fun resetEffects(keys: List<String>? = null, except: List<String> = emptyList()) {
synchronized(effectLock) {
effects.keys.removeAll { it !in except }
if (keys == null) {
effects.keys.removeAll { it !in except }
} else {
effects.keys.removeAll { it !in except && it in keys }
}
}
}

fun resetMemos(except: List<String> = emptyList()) {
/**
* Resets memos
* @param keys The keys to reset, if null all memos are reset
* @param except The keys to not reset
*/
fun resetMemos(keys: List<String>? = null, except: List<String> = emptyList()) {
synchronized(memoLock) {
memos.keys.removeAll { it !in except }
if (keys == null) {
memos.keys.removeAll { it !in except }
} else {
memos.keys.removeAll { it !in except && it in keys }
}
}
}

Expand Down

0 comments on commit 9996b93

Please sign in to comment.