ObservableCache 1.2.4
dotnet add package ObservableCache --version 1.2.4
NuGet\Install-Package ObservableCache -Version 1.2.4
<PackageReference Include="ObservableCache" Version="1.2.4" />
<PackageVersion Include="ObservableCache" Version="1.2.4" />
<PackageReference Include="ObservableCache" />
paket add ObservableCache --version 1.2.4
#r "nuget: ObservableCache, 1.2.4"
#:package ObservableCache@1.2.4
#addin nuget:?package=ObservableCache&version=1.2.4
#tool nuget:?package=ObservableCache&version=1.2.4
ObservableCache
A reactive, write-through observable cache for F# backed by Rx.NET. Supports CRUD operations with correlation IDs, grouped eviction, and automatic database persistence.
Installation
dotnet add package ObservableCache
Overview
ObservableCache sits between your application and your database. Operations flow in as an IObservable<Input>, items are cached in memory, and persistence to the database is handled automatically on eviction. Each operation carries a CorrelationId so results can be matched back to the caller.
How it works
- Create / Update — items are written to the in-memory cache immediately and persisted to the database when evicted.
- Read — items are served from the cache if present; otherwise fetched from the database and cached.
- Delete — items are removed from the cache immediately and deleted from the database.
- Eviction — items are evicted (and persisted) after a configurable idle
TimeSpanwith no activity, or immediately on delete.
Usage
Low-level: obsCache
Takes an IObservable<Input> and returns an IObservable<Guid * CacheOutput>.
open ObservableCache
open System
open System.Reactive.Subjects
open FSharp.Control.Reactive
let inputSubject = new Subject<Input<MyItem, Guid, MyItemMsg>>()
let outputObservable =
obsCache
saveToDatabase // MyItem -> IObservable<Result<MyItem, string>>
loadFromDatabase // Guid -> IObservable<Result<MyItem, string>>
deleteFromDatabase // Guid -> IObservable<Result<unit, string>>
applyMessage // MyItemMsg -> MyItem -> MyItem
(TimeSpan.FromSeconds 30.0)
inputSubject
High-level: createHelperFunctions
Returns four typed dispatch functions and the raw output observable — the recommended entry point for most use cases.
open ObservableCache
open System
let createItem, readItem, updateItem, deleteItem, outputObservable =
createHelperFunctions
saveToDatabase // MyItem -> IObservable<Result<MyItem, string>>
loadFromDatabase // Guid -> IObservable<Result<MyItem, string>>
deleteFromDatabase // Guid -> IObservable<Result<unit, string>>
applyMessage // MyItemMsg -> MyItem -> MyItem
(TimeSpan.FromSeconds 30.0)
// Dispatch functions return Tasks
let result: Task<Result<MyItem, string>> = createItem (id, item)
let result: Task<Result<MyItem, string>> = readItem id
let result: Task<Result<MyItem, string>> = updateItem (id, msg)
let result: Task<Result<unit, string>> = deleteItem id
// outputObservable emits all cache operations as (CorrelationId * CacheOutput) pairs
API
Types
| Type | Description |
|---|---|
CacheInput<'Item, 'ItemId, 'ItemMsg> |
Discriminated union of CreateItem, ReadItem, UpdateItem, DeleteItem |
Input<'Item, 'ItemId, 'ItemMsg> |
A CacheInput with a CorrelationId: Guid |
CacheOutput<'ItemId, 'Item> |
CreateItemOnDB, ReadItemOnDB, UpdateItemOnDB, DeleteItemOnDB — each carrying the 'ItemId and a Result |
Output<'ItemId, 'Item> |
A CacheOutput with a CorrelationId: Guid |
Functions
| Function | Signature |
|---|---|
obsCache |
('Item -> IObservable<Result<'Item, string>>) -> ('ItemId -> IObservable<Result<'Item, string>>) -> ('ItemId -> IObservable<Result<unit, string>>) -> ('ItemMsg -> 'Item -> 'Item) -> TimeSpan -> IObservable<Input<'Item, 'ItemId, 'ItemMsg>> -> IObservable<Guid * CacheOutput<'ItemId, 'Item>> |
createHelperFunctions |
Same first five parameters; returns (('ItemId * 'Item) -> Task<Result<'Item, string>>) * ('ItemId -> Task<Result<'Item, string>>) * (('ItemId * 'ItemMsg) -> Task<Result<'Item, string>>) * ('ItemId -> Task<Result<unit, string>>) * IObservable<Guid * CacheOutput<'ItemId, 'Item>> |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- FSharp.Control.Reactive (>= 6.1.2)
- FSharp.Core (>= 10.1.300)
- System.Reactive (>= 6.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.