Socket
Book a DemoInstallSign in
Socket

DistributedCache.AzureTableStorage

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

DistributedCache.AzureTableStorage

Distributed cache implementation of Microsoft.Extensions.Caching.Distributed.IDistributedCache using Azure Table Storage.

Source
nugetNuGet
Version
3.4.0
Version published
Maintainers
1
Created
Source

DistributedCache.AzureTableStorage

  • Based on oceanweb/azuretablestoragecache but with lower dependencies.
  • Extra added logic to use strongly typed objects with IDistributedCache instead of byte arrays.

Code example

Configure in code (option 1)

c# code:

// Configure in code
services.Configure<AzureTableStorageCacheOptions>(options =>
{
    options.TableName = "CacheTest";
    options.PartitionKey = "ConsoleApp";
    options.ConnectionString = "UseDevelopmentStorage=true;";
    options.ExpiredItemsDeletionInterval = TimeSpan.FromHours(24);
});

Notes

  • If the TableName does not exists, it's created. If you want to disable this behaviour, set the options.CreateTableIfNotExists to false.
  • When an item is retrieved or added to to the cache, a periodic interval scan can be done to find and delete expired items in the cache. Default this is set to null, which means that this functionality is disabled. If you want to change this, set the options.ExpiredItemsDeletionInterval to a different value, like TimeSpan.FromMinutes(30).

Configure via appsettings.json (option 2)

appsettings.json:

"AzureTableStorageCacheOptions": {
  "ConnectionString": "UseDevelopmentStorage=true;",
  "TableName": "CacheTest",
  "PartitionKey": "ConsoleApp"
}

c# code:

// Configure via app.setttings
services.Configure<AzureTableStorageCacheOptions>(Configuration.GetSection("AzureTableStorageCacheOptions"));

Add DistributedAzureTableStorageCache to services

services.AddDistributedAzureTableStorageCache();

Usage

IDistributedCache cache = ... // injected via DI

var test = new TestModel
{
    Id = 1,
    Name = "Test 1"
};

// Set an item in the cache using an expiration from 30 seconds
var cacheOptions = new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(30) };
await cache.SetAsync("t1", test, cacheOptions);

// Retrieve the item from the cache
var t2 = await cache.GetAsync<TestModel>("t1");
logger.LogInformation("t2 : {TestModel}", JsonConvert.SerializeObject(t2));

Sponsors

Entity Framework Extensions and Dapper Plus are major sponsors and proud to contribute to the development of DistributedCache.AzureTableStorage.

Entity Framework Extensions

Dapper Plus

Keywords

Distributed

FAQs

Package last updated on 31 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts