ObservableCache 2.0.1

dotnet add package ObservableCache --version 2.0.1
                    
NuGet\Install-Package ObservableCache -Version 2.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ObservableCache" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ObservableCache" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ObservableCache" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ObservableCache --version 2.0.1
                    
#r "nuget: ObservableCache, 2.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ObservableCache@2.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ObservableCache&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=ObservableCache&version=2.0.1
                    
Install as a Cake Tool

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 processed concurrently across keys but sequentially per key. The 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

  1. Create / Update — items are written to the per-key cache state immediately and persisted to the database when evicted.
  2. Read — items are served from the per-key cache state if present; otherwise fetched from the database and cached.
  3. Delete — items are removed from the per-key cache state immediately and deleted from the database.
  4. Eviction — items are evicted (and persisted) after a configurable idle TimeSpan with no activity, or immediately on delete.
  5. Concurrency — operations for the same key are processed sequentially; operations for different keys may run concurrently.

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

type MyItem = { Id: Guid; Name: string }
type MyItemMsg =
    | Rename of string

let update (msg: MyItemMsg) (item: MyItem) =
    match msg with
    | Rename name -> { item with Name = name }

let inputSubject = new Subject<Input<MyItem, Guid, MyItemMsg>>()

let updateItemOnDatabase (item: MyItem) : Async<Result<MyItem, string>> =
    // Persist the item here.
    Ok item |> async.Return

let readItemOnDatabase (id: Guid) : Async<Result<MyItem, string>> =
    // Load the item here.
    Ok { Id = id; Name = "loaded" } |> async.Return

let deleteItemOnDatabase (id: Guid) : Async<Result<unit, string>> =
    // Delete the item here.
    Ok () |> async.Return

let outputObservable =
    obsCache
        updateItemOnDatabase
        readItemOnDatabase
        deleteItemOnDatabase
        update
        (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 id = Guid.NewGuid()
let item = { Id = id; Name = "created" }
let msg = Rename "updated"

let createItem, readItem, updateItem, deleteItem, outputObservable =
    createHelperFunctions
        updateItemOnDatabase // MyItem -> Async<Result<MyItem, string>>
        readItemOnDatabase // Guid   -> Async<Result<MyItem, string>>
        deleteItemOnDatabase  // Guid   -> Async<Result<unit, string>>
        update        // MyItemMsg -> MyItem -> MyItem
        (TimeSpan.FromSeconds 30.0)

let createResult = createItem (id, item)
let readResult = readItem id
let updateResult = updateItem (id, msg)
let deleteResult = 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 -> Async<Result<'Item, string>>) -> ('ItemId -> Async<Result<'Item, string>>) -> ('ItemId -> Async<Result<unit, string>>) -> ('ItemMsg -> 'Item -> 'Item) -> TimeSpan -> IObservable<Input<'Item, 'ItemId, 'ItemMsg>> -> IObservable<Guid * CacheOutput<'ItemId, 'Item>>
createHelperFunctions Same first five parameters; returns typed create, read, update, and delete helper functions plus an IObservable<Guid * CacheOutput<'ItemId, 'Item>>

Notes

  • Database callbacks return Async<Result<_, string>>; ObservableCache converts them into observables internally where needed.
  • Use createHelperFunctions when callers need typed CRUD helpers.
  • Use obsCache directly when you already have an observable input stream and want to subscribe to all raw cache outputs.
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 83 6/10/2026
2.0.0 62 6/10/2026
1.3.0 72 6/8/2026
1.2.5 87 6/6/2026
1.2.4 66 6/4/2026
1.2.1 89 5/29/2026
1.2.0 66 5/29/2026
1.1.0 63 5/29/2026
1.0.2 64 5/29/2026
1.0.1 65 5/29/2026