Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support FasterKv options #518

Merged
merged 2 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

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
Loading