Skip to main content

Snapshot Providers

Snapshot providers store feature flag definitions locally, enabling faster startup and continued operation during temporary API outages.

Entity Framework​

Store snapshots in any database supported by Entity Framework Core (SQL Server, PostgreSQL, MySQL, SQLite, etc.).

Install-Package Toggly.FeatureManagement.Storage.EntityFramework
using Toggly.FeatureManagement.Storage.EntityFramework.Configuration;

services.AddTogglyEntityFrameworkSnapshotProvider(
options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))
);

With Custom Settings​

services.AddTogglyEntityFrameworkSnapshotProvider(
options => options.UseSqlServer(connectionString),
settings => {
settings.DocumentName = "my_features";
settings.JwkDocumentName = "my_jwks";
settings.AutoCreateTable = true; // Default
}
);
info

The provider creates a TogglySnapshots table automatically. Set AutoCreateTable = false if you prefer to manage the schema yourself.

RavenDB​

Store snapshots in RavenDB for document-oriented storage.

Install-Package Toggly.FeatureManagement.Storage.RavenDB
using Toggly.FeatureManagement.Storage.RavenDB.Configuration;

services.AddTogglyRavenDbSnapshotProvider();
info

The RavenDB Snapshot provider expects an instance of IDocumentStore injected via dependency injection.

Dapper​

Lightweight, high-performance SQL storage using Dapper. Supports SQL Server, PostgreSQL, MySQL, and SQLite.

info

Custom TableName values must be SQL identifiers (^[A-Za-z_][A-Za-z0-9_]*$, max 128). Unsafe names are rejected to prevent SQL injection via configuration.

Install-Package Toggly.FeatureManagement.Storage.Dapper

SQL Server​

using Toggly.FeatureManagement.Storage.Dapper.Configuration;
using Microsoft.Data.SqlClient;

services.AddTogglyDapperSnapshotProvider(
() => new SqlConnection(Configuration.GetConnectionString("DefaultConnection")),
options => options.Provider = DatabaseProvider.SqlServer
);

PostgreSQL​

using Npgsql;

services.AddTogglyDapperSnapshotProvider(
() => new NpgsqlConnection(Configuration.GetConnectionString("PostgresConnection")),
options => options.Provider = DatabaseProvider.PostgreSql
);

MySQL​

using MySqlConnector;

services.AddTogglyDapperSnapshotProvider(
() => new MySqlConnection(Configuration.GetConnectionString("MySqlConnection")),
options => options.Provider = DatabaseProvider.MySql
);

SQLite​

using Microsoft.Data.Sqlite;

services.AddTogglyDapperSnapshotProvider(
() => new SqliteConnection("Data Source=toggly.db"),
options => options.Provider = DatabaseProvider.Sqlite
);

MongoDB​

Store snapshots in MongoDB for high availability and horizontal scalability.

Install-Package Toggly.FeatureManagement.Storage.MongoDB
using Toggly.FeatureManagement.Storage.MongoDB.Configuration;

services.AddTogglyMongoDBSnapshotProvider(
Configuration.GetConnectionString("MongoDB")
);

With Custom Settings​

services.AddTogglyMongoDBSnapshotProvider(
"mongodb://localhost:27017",
options => {
options.DatabaseName = "my_app";
options.CollectionName = "feature_flags";
options.DocumentName = "my_features";
options.JwkDocumentName = "my_jwks";
}
);

With Existing MongoClient​

var mongoClient = new MongoClient(connectionString);

services.AddTogglyMongoDBSnapshotProvider(mongoClient, options => {
options.DatabaseName = "toggly";
});

Distributed Cache​

Store snapshots using ASP.NET Core's IDistributedCache interface.

Install-Package Toggly.FeatureManagement.Storage.DistributedCache
using Toggly.FeatureManagement.Storage.DistributedCache.Configuration;

// First configure a distributed cache (Redis, SQL Server, etc.)
services.AddStackExchangeRedisCache(options => {
options.Configuration = "localhost:6379";
});

// Then add the snapshot provider
services.AddTogglyDistributedCacheSnapshotProvider();

Clearing snapshots​

All providers implement ClearSnapshotAsync and ClearJwkSnapshotAsync to delete persisted cache documents/keys (for example RavenDB FeatureSnapshots/Toggly-Production).

// From a resolved service provider (e.g. WebApplication.Services)
var snapshots = app.Services.GetRequiredService<IFeatureSnapshotProvider>();
await snapshots.ClearSnapshotAsync();
await snapshots.ClearJwkSnapshotAsync();

// Or via the feature provider
var featureProvider = app.Services.GetRequiredService<TogglyFeatureProvider>();
await featureProvider.ClearPersistedSnapshotsAsync();

Use clear when recovering from a corrupt snapshot, after signing-key issues, or in integration tests. The next successful refresh rewrites the snapshot including SignedDefsJson (raw signed defs) and ETag.

Signed definitions and storage​

When UseSignedDefinitions is enabled, snapshots store the exact signed defs JSON as SignedDefsJson. Cold-start verification uses those bytes — do not rely on re-serializing feature models. See Reliability.

Provider Comparison​

ProviderBest ForRequires
Entity FrameworkExisting EF Core appsDatabase + EF Core
RavenDBDocument-oriented appsRavenDB
DapperHigh-performance SQLDatabase + ADO.NET
MongoDBNoSQL, high availabilityMongoDB
Distributed CacheExisting cache infrastructureIDistributedCache