-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid incrementing cache hits for expired entries (#2159)
- Loading branch information
Showing
3 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"effect": patch | ||
--- | ||
|
||
Avoid incrementing cache hits for expired entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as it from "effect-test/utils/extend" | ||
import * as Cache from "effect/Cache" | ||
import * as Effect from "effect/Effect" | ||
import * as TestClock from "effect/TestClock" | ||
import { describe, expect } from "vitest" | ||
|
||
describe("Cache", () => { | ||
it.effect("should not increment cache hits on expired entries", () => | ||
Effect.gen(function*(_) { | ||
const cache = yield* _(Cache.make({ | ||
capacity: 100, | ||
timeToLive: "1 seconds", | ||
lookup: (n: number) => Effect.succeed(n) | ||
})) | ||
yield* _(cache.get(42)) | ||
yield* _(TestClock.adjust("2 seconds")) | ||
yield* _(cache.get(42)) | ||
const { hits, misses } = yield* _(cache.cacheStats) | ||
expect(hits).toBe(0) | ||
expect(misses).toBe(2) | ||
})) | ||
}) |