ObservableCache 1.2.4

dotnet add package ObservableCache --version 1.2.4
                    
NuGet\Install-Package ObservableCache -Version 1.2.4
                    
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="1.2.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ObservableCache" Version="1.2.4" />
                    
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 1.2.4
                    
#r "nuget: ObservableCache, 1.2.4"
                    
#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@1.2.4
                    
#: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=1.2.4
                    
Install as a Cake Addin
#tool nuget:?package=ObservableCache&version=1.2.4
                    
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 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

  1. Create / Update — items are written to the in-memory cache immediately and persisted to the database when evicted.
  2. Read — items are served from the cache if present; otherwise fetched from the database and cached.
  3. Delete — items are removed from the cache 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.

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 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
1.2.4 0 6/4/2026
1.2.1 75 5/29/2026
1.2.0 56 5/29/2026
1.1.0 51 5/29/2026
1.0.2 54 5/29/2026
1.0.1 53 5/29/2026