Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/EasyCaching.FasterKv/Configurations/FasterKvCachingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,21 @@ public class FasterKvCachingOptions : BaseProviderOptions
#else
Path.Combine(Environment.CurrentDirectory, $"EasyCaching-FasterKv-{System.Diagnostics.Process.GetCurrentProcess().Id}");
#endif


/// <summary>
/// Preallocate file
/// </summary>
public bool PreallocateFile { get; set; } = false;

/// <summary>
/// Delete file on close
/// </summary>
public bool DeleteFileOnClose { get; set; } = true;

/// <summary>
/// Try recover latest
/// </summary>
public bool TryRecoverLatest { get; set; } = false;

/// <summary>
/// Set Custom Store
Expand All @@ -59,8 +73,8 @@ internal LogSettings GetLogSettings(string name)
return new LogSettings
{
LogDevice = Devices.CreateLogDevice(Path.Combine(LogPath, name),
preallocateFile: true,
deleteOnClose: true),
preallocateFile: PreallocateFile,
deleteOnClose: DeleteFileOnClose),
PageSizeBits = PageSizeBit,
MemorySizeBits = MemorySizeBit,
ReadCacheSettings = new ReadCacheSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ void Configure(FasterKvCachingOptions x)
x.ReadCacheMemorySizeBit = fasterKvOptions.ReadCacheMemorySizeBit;
x.ReadCachePageSizeBit = fasterKvOptions.ReadCachePageSizeBit;
x.LogPath = fasterKvOptions.LogPath;
x.PreallocateFile = fasterKvOptions.PreallocateFile;
x.DeleteFileOnClose = fasterKvOptions.DeleteFileOnClose;
x.TryRecoverLatest = fasterKvOptions.TryRecoverLatest;
}

options.RegisterExtension(new FasterKvOptionsExtension(name, Configure));
Expand Down
22 changes: 18 additions & 4 deletions src/EasyCaching.FasterKv/DefaultFasterKvCachingProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,16 @@ public DefaultFasterKvCachingProvider(
{
var logSetting = options.GetLogSettings(name);
_logDevice = logSetting.LogDevice;
_fasterKv = new FasterKV<SpanByte, SpanByte>(_options.IndexCount, logSetting,
loggerFactory: loggerFactory);
_fasterKv = new FasterKV<SpanByte, SpanByte>(
_options.IndexCount,
logSetting,
loggerFactory: loggerFactory,
tryRecoverLatest: _options.TryRecoverLatest,
checkpointSettings: new CheckpointSettings()
{
CheckpointDir = options.LogPath + ".checkpoint"
}
);
}
else
{
Expand Down Expand Up @@ -364,12 +372,18 @@ private void Dispose(bool _)
{
session.Dispose();
}

_logDevice?.Dispose();

if (_options.CustomStore != _fasterKv)
{
if (_options.DeleteFileOnClose == false)
{
_fasterKv.TakeFullCheckpointAsync(CheckpointType.FoldOver).AsTask().GetAwaiter().GetResult();
}
_fasterKv.Dispose();
}

_logDevice?.Dispose();

_disposed = true;
}

Expand Down