mirror of
https://github.com/bitwarden/server
synced 2025-12-24 12:13:17 +00:00
Revert filescoped (#2227)
* Revert "Add git blame entry (#2226)" This reverts commit239286737d. * Revert "Turn on file scoped namespaces (#2225)" This reverts commit34fb4cca2a.
This commit is contained in:
@@ -1,47 +1,48 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
|
||||
namespace Bit.Core.Utilities;
|
||||
|
||||
public static class DistributedCacheExtensions
|
||||
namespace Bit.Core.Utilities
|
||||
{
|
||||
public static void Set<T>(this IDistributedCache cache, string key, T value)
|
||||
public static class DistributedCacheExtensions
|
||||
{
|
||||
Set(cache, key, value, new DistributedCacheEntryOptions());
|
||||
}
|
||||
|
||||
public static void Set<T>(this IDistributedCache cache, string key, T value,
|
||||
DistributedCacheEntryOptions options)
|
||||
{
|
||||
var bytes = JsonSerializer.SerializeToUtf8Bytes(value);
|
||||
cache.Set(key, bytes, options);
|
||||
}
|
||||
|
||||
public static Task SetAsync<T>(this IDistributedCache cache, string key, T value)
|
||||
{
|
||||
return SetAsync(cache, key, value, new DistributedCacheEntryOptions());
|
||||
}
|
||||
|
||||
public static Task SetAsync<T>(this IDistributedCache cache, string key, T value,
|
||||
DistributedCacheEntryOptions options)
|
||||
{
|
||||
var bytes = JsonSerializer.SerializeToUtf8Bytes(value);
|
||||
return cache.SetAsync(key, bytes, options);
|
||||
}
|
||||
|
||||
public static bool TryGetValue<T>(this IDistributedCache cache, string key, out T value)
|
||||
{
|
||||
var val = cache.Get(key);
|
||||
value = default;
|
||||
if (val == null) return false;
|
||||
try
|
||||
public static void Set<T>(this IDistributedCache cache, string key, T value)
|
||||
{
|
||||
value = JsonSerializer.Deserialize<T>(val);
|
||||
Set(cache, key, value, new DistributedCacheEntryOptions());
|
||||
}
|
||||
catch
|
||||
|
||||
public static void Set<T>(this IDistributedCache cache, string key, T value,
|
||||
DistributedCacheEntryOptions options)
|
||||
{
|
||||
return false;
|
||||
var bytes = JsonSerializer.SerializeToUtf8Bytes(value);
|
||||
cache.Set(key, bytes, options);
|
||||
}
|
||||
|
||||
public static Task SetAsync<T>(this IDistributedCache cache, string key, T value)
|
||||
{
|
||||
return SetAsync(cache, key, value, new DistributedCacheEntryOptions());
|
||||
}
|
||||
|
||||
public static Task SetAsync<T>(this IDistributedCache cache, string key, T value,
|
||||
DistributedCacheEntryOptions options)
|
||||
{
|
||||
var bytes = JsonSerializer.SerializeToUtf8Bytes(value);
|
||||
return cache.SetAsync(key, bytes, options);
|
||||
}
|
||||
|
||||
public static bool TryGetValue<T>(this IDistributedCache cache, string key, out T value)
|
||||
{
|
||||
var val = cache.Get(key);
|
||||
value = default;
|
||||
if (val == null) return false;
|
||||
try
|
||||
{
|
||||
value = JsonSerializer.Deserialize<T>(val);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user