Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BatcherCache, BatcherDictionary #390

Merged
merged 10 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Expose inner Cache, hide Load/Save
  • Loading branch information
bartelink committed Jun 6, 2023
commit d9ca64bf48f615879fa7b13c6a058473d7a07d78
7 changes: 5 additions & 2 deletions src/Equinox.Core/Cache.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type Cache private (inner: System.Runtime.Caching.MemoryCache) =
config.Add("cacheMemoryLimitMegabytes", string sizeMb);
Cache(new System.Runtime.Caching.MemoryCache(name, config))
// if there's a non-zero maxAge, concurrent read attempts share the roundtrip (and its fate, if it throws)
member _.Load(key, maxAge, isStale, policy, loadOrReload, ct) = task {
member internal _.Load(key, maxAge, isStale, policy, loadOrReload, ct) = task {
let loadOrReload maybeBaseState = task {
let act = System.Diagnostics.Activity.Current
if act <> null then act.AddCacheHit(ValueOption.isSome maybeBaseState) |> ignore
Expand All @@ -87,9 +87,12 @@ type Cache private (inner: System.Runtime.Caching.MemoryCache) =
let cacheSlot = getElseAddEmptyEntry key policy
return! cacheSlot.ReadThrough(maxAge, isStale, loadOrReload) }
// Newer values get saved; equal values update the last retrieval timestamp
member _.Save(key, isStale, policy, timestamp, token, state) =
member internal _.Save(key, isStale, policy, timestamp, token, state) =
addOrMergeCacheEntry isStale key policy timestamp (token, state)

/// Exposes the internal MemoryCache
member val Inner = inner

type [<NoComparison; NoEquality; RequireQualifiedAccess>] CachingStrategy =
/// Retain a single 'state per streamName.
/// Each cache hit for a stream renews the retention period for the defined <c>window</c>.
Expand Down
4 changes: 2 additions & 2 deletions src/Equinox.Core/Caching.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ type private Decorator<'event, 'state, 'context, 'cat when 'cat :> ICategory<'ev
let private mkKey prefix streamName =
prefix + streamName

let private policySlidingExpiration (slidingExpiration: TimeSpan) () =
let internal policySlidingExpiration (slidingExpiration: TimeSpan) () =
System.Runtime.Caching.CacheItemPolicy(SlidingExpiration = slidingExpiration)
let private policyFixedTimeSpan (period: TimeSpan) () =
let internal policyFixedTimeSpan (period: TimeSpan) () =
let expirationPoint = let creationDate = DateTimeOffset.UtcNow in creationDate.Add period
System.Runtime.Caching.CacheItemPolicy(AbsoluteExpiration = expirationPoint)
let private mapStrategy = function
Expand Down