ValkeyBuilderExtensions.WithPersistence Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Configures a Valkey container resource for persistence.
public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ValkeyResource> WithPersistence (this Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ValkeyResource> builder, TimeSpan? interval = default, long keysChangedThreshold = 1);
static member WithPersistence : Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ValkeyResource> * Nullable<TimeSpan> * int64 -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ValkeyResource>
<Extension()>
Public Function WithPersistence (builder As IResourceBuilder(Of ValkeyResource), Optional interval As Nullable(Of TimeSpan) = Nothing, Optional keysChangedThreshold As Long = 1) As IResourceBuilder(Of ValkeyResource)
Parameters
- builder
- IResourceBuilder<ValkeyResource>
The resource builder.
- keysChangedThreshold
- Int64
The number of key change operations required to trigger a snapshot at the interval. Defaults to 1.
Returns
The IResourceBuilder<T>.
Examples
Use with WithDataBindMount(IResourceBuilder<ValkeyResource>, String, Boolean) or WithDataVolume(IResourceBuilder<ValkeyResource>, String, Boolean) to persist Valkey data across sessions with custom persistence configuration, e.g.:
var cache = builder.AddValkey("cache")
.WithDataVolume()
.WithPersistence(TimeSpan.FromSeconds(10), 5);