-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added: initial cache implementation.
- Loading branch information
Showing
15 changed files
with
223 additions
and
104 deletions.
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
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
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,37 @@ | ||
module Equinox.Microsoft.Extensions.Caching | ||
|
||
open System | ||
open Equinox.Store | ||
open Microsoft.Extensions.Caching.Memory | ||
|
||
type Cache(cache: IMemoryCache, valueSizeCalculator: (Object -> int64) option) = | ||
new (cache: IMemoryCache) = Cache(cache, None) | ||
|
||
interface ICache with | ||
member this.UpdateIfNewer cacheItemOptions key entry = | ||
let setExpiration (cacheEntry: ICacheEntry) (cacheItemOption: CacheItemOptions) = | ||
match cacheItemOption with | ||
| AbsoluteExpiration absolute -> cacheEntry.AbsoluteExpiration <- Nullable absolute | ||
| RelativeExpiration relative -> cacheEntry.SlidingExpiration <- Nullable relative | ||
match cache.GetOrCreate (key, fun cacheItem -> | ||
let (_, targetObject) = entry.Value | ||
cacheItem.Size <- | ||
match valueSizeCalculator with | ||
| Some (calculator) -> Nullable(calculator targetObject) | ||
| None -> Nullable<int64>() | ||
setExpiration cacheItem cacheItemOptions | ||
entry) | ||
with | ||
| null -> async.Return() | ||
| :? (CacheEntry<'state>) as existingEntry | ||
-> existingEntry.UpdateIfNewer entry | ||
async.Return() | ||
| x -> failwithf "UpdateIfNewer Incompatible cache entry %A" x | ||
|
||
member this.TryGet key = | ||
async.Return ( | ||
match cache.Get key with | ||
| null -> None | ||
| :? (CacheEntry<'state>) as existingEntry -> Some existingEntry.Value | ||
| x -> failwithf "TryGet Incompatible cache entry %A" x | ||
) |
26 changes: 26 additions & 0 deletions
26
src/Equinix.Microsoft.Extensions.Caching/Equinox.Microsoft.Extensions.Caching.fsproj
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,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<GenerateDocumentationFile Condition=" '$(Configuration)' == 'Release' ">true</GenerateDocumentationFile> | ||
<WarningLevel>5</WarningLevel> | ||
<IsTestProject>false</IsTestProject> | ||
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference> | ||
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="Cache.fs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="2.1.0" /> | ||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-18618-05" PrivateAssets="All" /> | ||
<PackageReference Include="MinVer" Version="1.0.0" PrivateAssets="All" /> | ||
|
||
<PackageReference Include="FSharp.Core" Version="3.1.2.5" Condition=" '$(TargetFramework)' == 'net461' " /> | ||
<PackageReference Include="FSharp.Core" Version="4.3.4" Condition=" '$(TargetFramework)' == 'netstandard2.0' " /> | ||
<PackageReference Include="Serilog" Version="2.7.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Equinox\Equinox.fsproj" /> | ||
</ItemGroup> | ||
</Project> |
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
Oops, something went wrong.