Skip to main content
.NETStandard2.0.NETStandard2.1

Fix Microsoft.Extensions.Caching.Memory.MemoryCache not being typesafe or allowing loader functions. Inspired by Guava Cache.

Published
Nov 6, 2025
11mo ago
Total Downloads
1.3K
1,295

Install

dotnet add package Unfucked.Caching --version 0.0.1-beta.2
ProductVersions
.NET Standard
netstandard2.0netstandard2.1

README

🧰 Unfucked.Caching

NuGet GitHub Actions Testspace Coveralls

Type-safe in-memory cache with optional automatic loaders. Inspired by Guava Cache.

Unfuck your house

Installation

dotnet add package Unfucked.Caching
using Unfucked.Caching;

Usage

Setting and getting values

Manual
using Cache<string, int> cache = new InMemoryCache<string, int>();

await cache.Put("a", 1);
int length = await cache.Get("a");
Semi-automatic
using Cache<string, int> cache = new InMemoryCache<string, int>();

int length = await cache.Get("a", async str => str.Length);
Automatic
using Cache<string, int> cache = new InMemoryCache<string, int>(loader: async str => str.Length);

int length = await cache.Get("a");

Expiration

Manual
cache.Invalidate("a");
cache.InvalidateAll();
Expire after last write
using Cache<string, int> cache = new InMemoryCache<string, int>(options: new CacheOptions {
    ExpireAfterWrite: TimeSpan.FromHours(1)
});
Expire after last read
using Cache<string, int> cache = new InMemoryCache<string, int>(options: new CacheOptions {
    ExpireAfterRead: TimeSpan.FromHours(1)
});
Automatically refresh after last write
using Cache<string, int> cache = new InMemoryCache<string, int>(options: new CacheOptions {
    RefreshAfterWrite: TimeSpan.FromHours(1)
});

All Unfucked libraries

Changes from Previous Version

v0.0.1-beta.1v0.0.1-beta.2
Added Frameworks
.NETStandard2.1
Added Dependencies

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 2 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.