Skip to content
This repository was archived by the owner on Dec 1, 2025. It is now read-only.

Commit f3c866d

Browse files
committed
Initial Commit
1 parent 58550b2 commit f3c866d

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

src/CacheFlow/Core/BufferCacheProvider.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System.Buffers;
21
using CacheFlow.Abstractions;
32
using CacheFlow.Internal.Buffers;
43
using Microsoft.Extensions.Logging;
4+
using System.Buffers;
55

66
namespace CacheFlow.Core
77
{
@@ -25,7 +25,9 @@ public async ValueTask<bool> TryGetBufferAsync(string key, IBufferWriter<byte> w
2525
{
2626
byte[]? buffer = await _innerProvider.GetAsync<byte[]>(key, token);
2727
if (buffer == null)
28+
{
2829
return false;
30+
}
2931

3032
Span<byte> span = writer.GetSpan(buffer.Length);
3133
buffer.CopyTo(span);
@@ -45,7 +47,7 @@ public async ValueTask SetBufferAsync(string key, ReadOnlySequence<byte> value,
4547
{
4648
try
4749
{
48-
using RecyclableArrayBufferWriter<byte> writer = new RecyclableArrayBufferWriter<byte>((int)value.Length);
50+
using RecyclableArrayBufferWriter<byte> writer = new((int)value.Length);
4951
foreach (ReadOnlyMemory<byte> segment in value)
5052
{
5153
Span<byte> span = writer.GetSpan(segment.Length);
@@ -97,20 +99,30 @@ public ValueTask SetBufferAsync(string key, ReadOnlyMemory<byte> value,
9799
}
98100

99101
// ICacheProvider implementation
100-
public ValueTask<T?> GetAsync<T>(string key, CancellationToken token = default) =>
101-
_innerProvider.GetAsync<T>(key, token);
102+
public ValueTask<T?> GetAsync<T>(string key, CancellationToken token = default)
103+
{
104+
return _innerProvider.GetAsync<T>(key, token);
105+
}
102106

103107
public ValueTask SetAsync<T>(string key, T value, DateTimeOffset? absoluteExpiration = null,
104-
TimeSpan? slidingExpiration = null, CancellationToken token = default) =>
105-
_innerProvider.SetAsync(key, value, absoluteExpiration, slidingExpiration, token);
108+
TimeSpan? slidingExpiration = null, CancellationToken token = default)
109+
{
110+
return _innerProvider.SetAsync(key, value, absoluteExpiration, slidingExpiration, token);
111+
}
106112

107-
public ValueTask RemoveAsync(string key, CancellationToken token = default) =>
108-
_innerProvider.RemoveAsync(key, token);
113+
public ValueTask RemoveAsync(string key, CancellationToken token = default)
114+
{
115+
return _innerProvider.RemoveAsync(key, token);
116+
}
109117

110-
public ValueTask<bool> ExistsAsync(string key, CancellationToken token = default) =>
111-
_innerProvider.ExistsAsync(key, token);
118+
public ValueTask<bool> ExistsAsync(string key, CancellationToken token = default)
119+
{
120+
return _innerProvider.ExistsAsync(key, token);
121+
}
112122

113-
public ValueTask RefreshAsync(string key, CancellationToken token = default) =>
114-
_innerProvider.RefreshAsync(key, token);
123+
public ValueTask RefreshAsync(string key, CancellationToken token = default)
124+
{
125+
return _innerProvider.RefreshAsync(key, token);
126+
}
115127
}
116128
}

src/CacheFlow/Extensions/BufferCacheExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ public static IServiceCollection AddBufferCache(this IServiceCollection services
4747
public static IBufferCacheProvider WithBufferSupport(this ICacheProvider provider, ILogger<BufferCacheProvider> logger)
4848
{
4949
if (provider == null)
50+
{
5051
throw new ArgumentNullException(nameof(provider));
52+
}
5153

5254
if (logger == null)
55+
{
5356
throw new ArgumentNullException(nameof(logger));
57+
}
5458

5559
return new BufferCacheProvider(provider, logger);
5660
}

src/CacheFlow/Internal/Buffers/BufferChunk.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public BufferChunk(int minimumLength)
4949
/// The returned Memory instance represents a view over the rented array,
5050
/// limited to the requested minimum length from the constructor.
5151
/// </remarks>
52-
public Memory<T> Array => new Memory<T>(_rentedArray, 0, Length);
52+
public Memory<T> Array => new(_rentedArray, 0, Length);
5353

5454
/// <summary>
5555
/// Gets the length of the usable portion of the buffer.

0 commit comments

Comments
 (0)