Skip to content

Commit 7aa4e1b

Browse files
committed
Fixed styling issues according to code review.
1 parent 0986670 commit 7aa4e1b

File tree

4 files changed

+33
-41
lines changed

4 files changed

+33
-41
lines changed

src/Equinox.Core/Cache.fs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,32 @@ type ICache =
2525
abstract member TryGet: key: string -> Async<(StreamToken * 'state) option>
2626

2727
namespace Equinox
28+
2829
open System.Runtime.Caching
2930
open Equinox.Core
31+
3032
type Cache(name, sizeMb : int) =
3133
let cache =
3234
let config = System.Collections.Specialized.NameValueCollection(1)
3335
config.Add("cacheMemoryLimitMegabytes", string sizeMb);
3436
new MemoryCache(name, config)
3537

36-
let getPolicy (cacheItemOption: CacheItemOptions)=
38+
let getPolicy (cacheItemOption: CacheItemOptions) =
3739
match cacheItemOption with
3840
| AbsoluteExpiration absolute -> new CacheItemPolicy(AbsoluteExpiration = absolute)
3941
| RelativeExpiration relative -> new CacheItemPolicy(SlidingExpiration = relative)
4042

4143
interface ICache with
42-
43-
member this.UpdateIfNewer cacheItemOptions key entry =
44+
member this.UpdateIfNewer cacheItemOptions key entry = async {
4445
let policy = getPolicy cacheItemOptions
4546
match cache.AddOrGetExisting(key, box entry, policy) with
46-
| null ->
47-
async.Return ()
47+
| null -> ()
4848
| :? CacheEntry<'state> as existingEntry -> existingEntry.UpdateIfNewer entry
49-
async.Return ()
50-
| x -> failwithf "UpdateIfNewer Incompatible cache entry %A" x
49+
| x -> failwithf "UpdateIfNewer Incompatible cache entry %A" x }
5150

52-
member this.TryGet key =
53-
async.Return (
51+
member this.TryGet key = async {
52+
return
5453
match cache.Get key with
5554
| null -> None
5655
| :? CacheEntry<'state> as existingEntry -> Some existingEntry.Value
57-
| x -> failwithf "TryGet Incompatible cache entry %A" x
58-
)
56+
| x -> failwithf "TryGet Incompatible cache entry %A" x }

src/Equinox.Core/Equinox.Core.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
<PackageReference Include="FSharp.Core" Version="3.1.2.5" Condition=" '$(TargetFramework)' != 'netstandard2.0' " />
3131
<PackageReference Include="FSharp.Core" Version="4.3.4" Condition=" '$(TargetFramework)' == 'netstandard2.0' " />
32-
<PackageReference Include="System.Runtime.Caching" Version="4.6.0" />
32+
<PackageReference Include="System.Runtime.Caching" Version="4.6.0" Condition=" '$(TargetFramework)' == 'netstandard2.0' "/>
3333
</ItemGroup>
3434

3535
</Project>

src/Equinox.Cosmos/Cosmos.fs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,6 @@ open Microsoft.Azure.Documents
775775
open Serilog
776776
open System
777777
open System.Collections.Concurrent
778-
open System.Runtime.Caching
779778

780779
/// Defines policies for retrying with respect to transient failures calling CosmosDb (as opposed to application level concurrency conflicts)
781780
type Connection(client: Client.DocumentClient, [<O; D(null)>]?readRetryPolicy: IRetryPolicy, [<O; D(null)>]?writeRetryPolicy) =
@@ -898,16 +897,15 @@ module Caching =
898897
let! intercepted = intercept stream (token', state')
899898
return SyncResult.Written(intercepted) }
900899

901-
902900
let applyCacheUpdatesWithSlidingExpiration
903901
(cache: ICache)
904902
(prefix: string)
905903
(slidingExpiration : TimeSpan)
906904
(category: ICategory<'event, 'state, Container*string>)
907905
: ICategory<'event, 'state, Container*string> =
908-
let cacheEntryGenerator (initialToken: StreamToken, initialState: 'state) = new CacheEntry<'state>(initialToken, initialState, Token.supersedes)
906+
let mkCacheEntry (initialToken: StreamToken, initialState: 'state) = new CacheEntry<'state>(initialToken, initialState, Token.supersedes)
909907
let policy = CacheItemOptions.RelativeExpiration(slidingExpiration)
910-
let addOrUpdateSlidingExpirationCacheEntry streamName = cacheEntryGenerator >> cache.UpdateIfNewer policy (prefix + streamName)
908+
let addOrUpdateSlidingExpirationCacheEntry streamName = mkCacheEntry >> cache.UpdateIfNewer policy (prefix + streamName)
911909
CategoryTee<'event,'state>(category, addOrUpdateSlidingExpirationCacheEntry) :> _
912910

913911
type private Folder<'event, 'state>
@@ -918,17 +916,16 @@ type private Folder<'event, 'state>
918916
let inspectUnfolds = match mapUnfolds with Choice1Of3 () -> false | _ -> true
919917
interface ICategory<'event, 'state, Container*string> with
920918
member __.Load containerStream (log : ILogger): Async<StreamToken * 'state> = async {
921-
let! batched = category.Load inspectUnfolds containerStream fold initial isOrigin log
922-
let cached tokenAndState = category.LoadFromToken tokenAndState fold isOrigin log
923-
match readCache with
919+
let! batched = category.Load inspectUnfolds containerStream fold initial isOrigin log
920+
let cached tokenAndState = category.LoadFromToken tokenAndState fold isOrigin log
921+
match readCache with
922+
| None -> return batched
923+
| Some (cache : ICache, prefix : string) ->
924+
let! cacheItem = cache.TryGet(prefix + snd containerStream)
925+
match cacheItem with
924926
| None -> return batched
925-
| Some (cache : ICache, prefix : string) ->
926-
let! cacheItem = cache.TryGet(prefix + snd containerStream)
927-
match cacheItem with
928-
| None -> return batched
929-
| Some tokenAndState -> return! cached tokenAndState
930-
}
931-
member __.TrySync (log : ILogger) (streamToken,state) (events : 'event list)
927+
| Some tokenAndState -> return! cached tokenAndState }
928+
member __.TrySync (log : ILogger) (streamToken,state) (events : 'event list)
932929
: Async<SyncResult<'state>> = async {
933930
let! res = category.Sync((streamToken,state), events, mapUnfolds, fold, isOrigin, log)
934931
match res with

src/Equinox.EventStore/EventStore.fs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,7 @@ type private Category<'event, 'state>(context : Context, codec : FsCodec.IUnionE
444444
module Caching =
445445
/// Forwards all state changes in all streams of an ICategory to a `tee` function
446446
type CategoryTee<'event, 'state>(inner: ICategory<'event, 'state, string>, tee : string -> StreamToken * 'state -> Async<unit>) =
447-
let intercept streamName tokenAndState =
448-
async{
447+
let intercept streamName tokenAndState = async {
449448
let! _ = tee streamName tokenAndState
450449
return tokenAndState
451450
}
@@ -468,24 +467,22 @@ module Caching =
468467
(slidingExpiration : TimeSpan)
469468
(category: ICategory<'event, 'state, string>)
470469
: ICategory<'event, 'state, string> =
471-
let cacheEntryGenerator (initialToken: StreamToken, initialState: 'state) = new CacheEntry<'state>(initialToken, initialState, Token.supersedes)
470+
let mkCacheEntry (initialToken: StreamToken, initialState: 'state) = new CacheEntry<'state>(initialToken, initialState, Token.supersedes)
472471
let policy = CacheItemOptions.RelativeExpiration(slidingExpiration)
473-
let addOrUpdateSlidingExpirationCacheEntry streamName = cacheEntryGenerator >> cache.UpdateIfNewer policy (prefix + streamName)
472+
let addOrUpdateSlidingExpirationCacheEntry streamName = mkCacheEntry >> cache.UpdateIfNewer policy (prefix + streamName)
474473
CategoryTee<'event,'state>(category, addOrUpdateSlidingExpirationCacheEntry) :> _
475474

476475
type private Folder<'event, 'state>(category : Category<'event, 'state>, fold: 'state -> 'event seq -> 'state, initial: 'state, ?readCache) =
477-
let loadAlgorithm streamName initial log =
478-
async {
479-
let! batched = category.Load fold initial streamName log
480-
let cached token state = category.LoadFromToken fold state streamName token log
481-
match readCache with
476+
let loadAlgorithm streamName initial log = async {
477+
let! batched = category.Load fold initial streamName log
478+
let cached token state = category.LoadFromToken fold state streamName token log
479+
match readCache with
480+
| None -> return batched
481+
| Some (cache : ICache, prefix : string) ->
482+
let! cacheItem = cache.TryGet(prefix + streamName)
483+
match cacheItem with
482484
| None -> return batched
483-
| Some (cache : ICache, prefix : string) ->
484-
let! cacheItem = cache.TryGet(prefix + streamName)
485-
match cacheItem with
486-
| None -> return batched
487-
| Some (token, state) -> return! cached token state
488-
}
485+
| Some (token, state) -> return! cached token state }
489486
interface ICategory<'event, 'state, string> with
490487
member __.Load (streamName : string) (log : ILogger) : Async<StreamToken * 'state> =
491488
loadAlgorithm streamName initial log

0 commit comments

Comments
 (0)