diff --git a/CacheDrive.ExampleConsoleApp/appsettings.json b/CacheDrive.ExampleConsoleApp/appsettings.json
index 2903618..edb3c0e 100644
--- a/CacheDrive.ExampleConsoleApp/appsettings.json
+++ b/CacheDrive.ExampleConsoleApp/appsettings.json
@@ -5,6 +5,7 @@
"CacheExpirationType": "Minutes",
"CacheExpiration": 60,
"CacheType": "MemoryAndFile",
- "InitializeOnStartup": true
+ "InitializeOnStartup": true,
+ "FlushOnExit": true
}
}
\ No newline at end of file
diff --git a/CacheDrive/Configuration/CacheSettings.cs b/CacheDrive/Configuration/CacheSettings.cs
index 8c80e07..d3e26a4 100644
--- a/CacheDrive/Configuration/CacheSettings.cs
+++ b/CacheDrive/Configuration/CacheSettings.cs
@@ -39,4 +39,10 @@ public class CacheSettings
/// Default value is true.
///
public bool InitializeOnStartup { get; set; } = true;
+
+ ///
+ /// Before exit, flush the cache data to a files if necessary.
+ /// Default value is true.
+ ///
+ public bool FlushOnExit { get; set; } = true;
}
\ No newline at end of file
diff --git a/CacheDrive/Extensions/ServiceCollectionExtensions.cs b/CacheDrive/Extensions/ServiceCollectionExtensions.cs
index bebe88c..2749f8c 100644
--- a/CacheDrive/Extensions/ServiceCollectionExtensions.cs
+++ b/CacheDrive/Extensions/ServiceCollectionExtensions.cs
@@ -31,9 +31,12 @@ public static void RegisterCacheDrive(this IServiceCollection services,
services.Configure(opt =>
{
opt.CacheEnabled = settings.CacheEnabled;
+ opt.CacheFolderName = settings.CacheFolderName;
opt.CacheExpiration = settings.CacheExpiration;
opt.CacheExpirationType = settings.CacheExpirationType;
opt.CacheType = settings.CacheType;
+ opt.InitializeOnStartup = settings.InitializeOnStartup;
+ opt.FlushOnExit = settings.FlushOnExit;
});
}
else
@@ -48,9 +51,12 @@ public static void RegisterCacheDrive(this IServiceCollection services,
services.Configure(opt =>
{
opt.CacheEnabled = settings.CacheEnabled;
+ opt.CacheFolderName = settings.CacheFolderName;
opt.CacheExpiration = settings.CacheExpiration;
opt.CacheExpirationType = settings.CacheExpirationType;
opt.CacheType = settings.CacheType;
+ opt.InitializeOnStartup = settings.InitializeOnStartup;
+ opt.FlushOnExit = settings.FlushOnExit;
});
}
else
diff --git a/CacheDrive/Services/MemoryCacheFileStorageService.cs b/CacheDrive/Services/MemoryCacheFileStorageService.cs
index 2cf81c2..dbc6c8e 100644
--- a/CacheDrive/Services/MemoryCacheFileStorageService.cs
+++ b/CacheDrive/Services/MemoryCacheFileStorageService.cs
@@ -175,6 +175,9 @@ private void DisposeManageResource()
private void DisposeUnManageResource()
{
- Flush();
+ if (CacheSettings.FlushOnExit)
+ {
+ Flush();
+ }
}
}
\ No newline at end of file