Fix db access
- Add NuGet properties - Update RethinkDB F# driver
This commit is contained in:
parent
21ef9bac02
commit
26d7c9b140
|
@ -52,19 +52,19 @@ type DistributedRethinkDBCache (options : IOptions<DistributedRethinkDBCacheOpti
|
|||
let db = defaultArg (Option.ofObj opts.Database) ""
|
||||
|
||||
/// The table name; default to "Cache" if not provided
|
||||
let table = match defaultArg (Option.ofObj opts.TableName) "" with "" -> "Cache" | tbl -> tbl
|
||||
let tbl = match defaultArg (Option.ofObj opts.TableName) "" with "" -> "Cache" | tbl -> tbl
|
||||
|
||||
/// The name of the cache
|
||||
let cacheName =
|
||||
let table =
|
||||
seq {
|
||||
match db with "" -> () | _ -> $"{db}."
|
||||
table
|
||||
tbl
|
||||
}
|
||||
|> Seq.reduce (+)
|
||||
|
||||
/// Debug message
|
||||
let dbug text =
|
||||
if log.IsEnabled LogLevel.Debug then log.LogDebug $"[{cacheName}] %s{text ()}"
|
||||
if log.IsEnabled LogLevel.Debug then log.LogDebug $"[{table}] %s{text ()}"
|
||||
|
||||
/// Make sure the RethinkDB database, table, expiration index exist
|
||||
let checkEnvironment (_ : CancellationToken) =
|
||||
|
@ -84,23 +84,23 @@ type DistributedRethinkDBCache (options : IOptions<DistributedRethinkDBCacheOpti
|
|||
do! rethink { dbCreate db; write; withRetryDefault; ignoreResult opts.Connection }
|
||||
dbug <| fun () -> " ...done"
|
||||
// Table
|
||||
dbug <| fun () -> sprintf $" Checking for table {table} existence..."
|
||||
dbug <| fun () -> sprintf $" Checking for table {tbl} existence..."
|
||||
let! tables = rethink<string list> { tableList db; result; withRetryDefault opts.Connection }
|
||||
if not (tables |> List.contains table) then
|
||||
dbug <| fun () -> sprintf $" ...creating table {table}..."
|
||||
do! rethink { withDb db; tableCreate table; write; withRetryDefault; ignoreResult opts.Connection }
|
||||
if not (tables |> List.contains tbl) then
|
||||
dbug <| fun () -> sprintf $" ...creating table {tbl}..."
|
||||
do! rethink { tableCreate table; write; withRetryDefault; ignoreResult opts.Connection }
|
||||
dbug <| fun () -> " ...done"
|
||||
// Index
|
||||
dbug <| fun () -> sprintf $" Checking for index {table}.expiresAt..."
|
||||
dbug <| fun () -> sprintf $" Checking for index {tbl}.expiresAt..."
|
||||
let! indexes = rethink<string list> {
|
||||
withDb db; withTable table
|
||||
withTable table
|
||||
indexList
|
||||
result; withRetryDefault opts.Connection
|
||||
}
|
||||
if not (indexes |> List.contains "expiresAt") then
|
||||
dbug <| fun () -> sprintf $" ...creating index expiresAt on table {table}..."
|
||||
dbug <| fun () -> sprintf $" ...creating index expiresAt on table {tbl}..."
|
||||
do! rethink {
|
||||
withDb db; withTable table
|
||||
withTable table
|
||||
indexCreate "expiresAt"
|
||||
write; withRetryDefault; ignoreResult opts.Connection
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ type DistributedRethinkDBCache (options : IOptions<DistributedRethinkDBCacheOpti
|
|||
let tix = DateTime.UtcNow.Ticks - 1L
|
||||
dbug <| fun () -> $"Purging expired entries (<= %i{tix})"
|
||||
do! rethink {
|
||||
withDb db; withTable table
|
||||
withTable table
|
||||
between (r.Minval ()) tix [ BetweenOptArg.Index "expiresAt" ]
|
||||
delete
|
||||
write; withRetryDefault; ignoreResult opts.Connection
|
||||
|
@ -128,7 +128,7 @@ type DistributedRethinkDBCache (options : IOptions<DistributedRethinkDBCacheOpti
|
|||
/// Get the cache entry specified
|
||||
let getCacheEntry (key : string) (_ : CancellationToken) =
|
||||
rethink<CacheEntry> {
|
||||
withDb db; withTable table
|
||||
withTable table
|
||||
get key
|
||||
resultOption; withRetryDefault opts.Connection
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ type DistributedRethinkDBCache (options : IOptions<DistributedRethinkDBCacheOpti
|
|||
backgroundTask {
|
||||
if entry.slidingExpiration > 0 then
|
||||
do! rethink {
|
||||
withDb db; withTable table
|
||||
withTable table
|
||||
get entry.id
|
||||
update [ "expiresAt", ticksFromNow entry.slidingExpiration :> obj ]
|
||||
write; withRetryDefault; ignoreResult opts.Connection
|
||||
|
@ -177,7 +177,7 @@ type DistributedRethinkDBCache (options : IOptions<DistributedRethinkDBCacheOpti
|
|||
cnxToken.ThrowIfCancellationRequested ()
|
||||
do! checkEnvironment cnxToken
|
||||
do! rethink {
|
||||
withDb db; withTable table
|
||||
withTable table
|
||||
get key
|
||||
delete
|
||||
write; withRetryDefault; ignoreResult opts.Connection
|
||||
|
@ -208,21 +208,14 @@ type DistributedRethinkDBCache (options : IOptions<DistributedRethinkDBCacheOpti
|
|||
slidingExpiration = 0
|
||||
}
|
||||
|> addExpiration
|
||||
match! getCacheEntry key cnxToken with
|
||||
| None ->
|
||||
do! rethink {
|
||||
withDb db; withTable table
|
||||
insert entry
|
||||
write; withRetryDefault; ignoreResult opts.Connection
|
||||
}
|
||||
| Some _ ->
|
||||
do! rethink {
|
||||
withDb db; withTable table
|
||||
get key
|
||||
withTable table
|
||||
replace entry
|
||||
write; withRetryDefault; ignoreResult opts.Connection
|
||||
}
|
||||
}
|
||||
|
||||
/// Execute a task synchronously
|
||||
let runSync (task : CancellationToken -> Task<'T>) =
|
||||
task CancellationToken.None |> (Async.AwaitTask >> Async.RunSynchronously)
|
||||
|
||||
|
|
|
@ -9,11 +9,11 @@ open System
|
|||
|
||||
type IServiceCollection with
|
||||
|
||||
member this.AddDistributedRethinkDBCache(options : Action<DistributedRethinkDBCacheOptions>) =
|
||||
match options with null -> nullArg "options" | _ -> ()
|
||||
ignore <| this.AddOptions ()
|
||||
ignore <| this.Configure options
|
||||
ignore <| this.Add (ServiceDescriptor.Transient<IDistributedCache, DistributedRethinkDBCache>())
|
||||
member this.AddDistributedRethinkDBCache (options : Action<DistributedRethinkDBCacheOptions>) =
|
||||
if isNull options then nullArg "options"
|
||||
this.AddOptions () |> ignore
|
||||
this.Configure options |> ignore
|
||||
this.Add (ServiceDescriptor.Transient<IDistributedCache, DistributedRethinkDBCache> ())
|
||||
this
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -3,13 +3,25 @@
|
|||
<PropertyGroup>
|
||||
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<VersionPrefix>0.9.0</VersionPrefix>
|
||||
<VersionSuffix>alpha02</VersionSuffix>
|
||||
<Authors>danieljsummers</Authors>
|
||||
<PackageProjectUrl>https://github.com/danieljsummers/RethinkDB.DistributedCache</PackageProjectUrl>
|
||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||
<RepositoryUrl>https://github.com/danieljsummers/RethinkDB.DistributedCache</RepositoryUrl>
|
||||
<RepositoryType>Git</RepositoryType>
|
||||
<Copyright>MIT License</Copyright>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<PackageTags>RethinkDB IDistributedCache ASP.NET Core</PackageTags>
|
||||
<Description>An IDistributedCache implementation utilizing RethinkDB for storage</Description>
|
||||
<PackageReleaseNotes>Updated to .NET 6</PackageReleaseNotes>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="*" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
|
||||
<PackageReference Include="RethinkDb.Driver.FSharp" Version="0.8.0-alpha-0002" />
|
||||
<PackageReference Include="RethinkDb.Driver.FSharp" Version="0.8.0-alpha-0003" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Loading…
Reference in New Issue
Block a user