Skip to content

Commit

Permalink
Merge 13d1e98 into 5a6fbab
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-sunset committed Mar 18, 2023
2 parents 5a6fbab + 13d1e98 commit 7f2c021
Show file tree
Hide file tree
Showing 4 changed files with 371 additions and 68 deletions.
72 changes: 72 additions & 0 deletions src/FastCache.Cached/Cached.Save.cs
@@ -0,0 +1,72 @@
namespace FastCache;

public static partial class Cached<V>
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V Save<K>(K key, V value, TimeSpan expiration) where K : notnull =>
SaveInternal(key, value, expiration);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V Save<K>(K key, V value, TimeSpan expiration, uint limit) where K : notnull =>
SaveInternal(key, value, expiration, limit);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V Save<K1, K2>(K1 param1, K2 param2, V value, TimeSpan expiration) =>
SaveInternal((param1, param2), value, expiration);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V Save<K1, K2>(K1 param1, K2 param2, V value, TimeSpan expiration, uint limit) =>
SaveInternal((param1, param2), value, expiration, limit);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V Save<K1, K2, K3>(K1 param1, K2 param2, K3 param3, V value, TimeSpan expiration) =>
SaveInternal((param1, param2, param3), value, expiration);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V Save<K1, K2, K3>(K1 param1, K2 param2, K3 param3, V value, TimeSpan expiration, uint limit) =>
SaveInternal((param1, param2, param3), value, expiration, limit);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V Save<K1, K2, K3, K4>(K1 param1, K2 param2, K3 param3, K4 param4, V value, TimeSpan expiration) =>
SaveInternal((param1, param2, param3, param4), value, expiration);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V Save<K1, K2, K3, K4>(K1 param1, K2 param2, K3 param3, K4 param4, V value, TimeSpan expiration, uint limit) =>
SaveInternal((param1, param2, param3, param4), value, expiration, limit);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V Save<K1, K2, K3, K4, K5>(K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, V value, TimeSpan expiration) =>
SaveInternal((param1, param2, param3, param4, param5), value, expiration);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V Save<K1, K2, K3, K4, K5>(K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, V value, TimeSpan expiration, uint limit) =>
SaveInternal((param1, param2, param3, param4, param5), value, expiration, limit);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V Save<K1, K2, K3, K4, K5, K6>(K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, K6 param6, V value, TimeSpan expiration) =>
SaveInternal((param1, param2, param3, param4, param5, param6), value, expiration);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V Save<K1, K2, K3, K4, K5, K6>(K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, K6 param6, V value, TimeSpan expiration, uint limit) =>
SaveInternal((param1, param2, param3, param4, param5, param6), value, expiration, limit);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V Save<K1, K2, K3, K4, K5, K6, K7>(K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, K6 param6, K7 param7, V value, TimeSpan expiration) =>
SaveInternal((param1, param2, param3, param4, param5, param6, param7), value, expiration);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static V Save<K1, K2, K3, K4, K5, K6, K7>(K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, K6 param6, K7 param7, V value, TimeSpan expiration, uint limit) =>
SaveInternal((param1, param2, param3, param4, param5, param6, param7), value, expiration, limit);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static V SaveInternal<K>(K key, V value, TimeSpan expiration) where K : notnull
{
return new Cached<K, V>(key, default!, found: false).Save(value, expiration);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static V SaveInternal<K>(K key, V value, TimeSpan expiration, uint limit) where K : notnull
{
return new Cached<K, V>(key, default!, found: false).Save(value, expiration, limit);
}
}
2 changes: 1 addition & 1 deletion src/FastCache.Cached/Cached.TryGet.cs
@@ -1,6 +1,6 @@
namespace FastCache;

public static class Cached<V>
public static partial class Cached<V>
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryGet<K>(K key, out Cached<K, V> cached) where K : notnull
Expand Down
95 changes: 28 additions & 67 deletions src/FastCache.Cached/CachedExtensions.cs
Expand Up @@ -2,85 +2,46 @@ namespace FastCache.Extensions;

public static class CachedExtensions
{
public static V Cache<K, V>(this V value, K key, TimeSpan expiration) where K : notnull
{
return CacheInternal(key, value, expiration);
}
public static V Cache<K, V>(this V value, K key, TimeSpan expiration) where K : notnull =>
Cached<V>.Save(key, value, expiration);

public static V Cache<K, V>(this V value, K key, TimeSpan expiration, uint limit) where K : notnull
{
return CacheInternal(key, value, expiration, limit);
}
public static V Cache<K, V>(this V value, K key, TimeSpan expiration, uint limit) where K : notnull =>
Cached<V>.Save(key, value, expiration, limit);

public static V Cache<K1, K2, V>(this V value, K1 param1, K2 param2, TimeSpan expiration)
{
return CacheInternal((param1, param2), value, expiration);
}
public static V Cache<K1, K2, V>(this V value, K1 param1, K2 param2, TimeSpan expiration) =>
Cached<V>.Save(param1, param2, value, expiration);

public static V Cache<K1, K2, V>(this V value, K1 param1, K2 param2, TimeSpan expiration, uint limit)
{
return CacheInternal((param1, param2), value, expiration, limit);
}
public static V Cache<K1, K2, V>(this V value, K1 param1, K2 param2, TimeSpan expiration, uint limit) =>
Cached<V>.Save(param1, param2, value, expiration, limit);

public static V Cache<K1, K2, K3, V>(this V value, K1 param1, K2 param2, K3 param3, TimeSpan expiration)
{
return CacheInternal((param1, param2, param3), value, expiration);
}
public static V Cache<K1, K2, K3, V>(this V value, K1 param1, K2 param2, K3 param3, TimeSpan expiration) =>
Cached<V>.Save(param1, param2, param3, value, expiration);

public static V Cache<K1, K2, K3, V>(this V value, K1 param1, K2 param2, K3 param3, TimeSpan expiration, uint limit)
{
return CacheInternal((param1, param2, param3), value, expiration, limit);
}
public static V Cache<K1, K2, K3, V>(this V value, K1 param1, K2 param2, K3 param3, TimeSpan expiration, uint limit) =>
Cached<V>.Save(param1, param2, param3, value, expiration, limit);

public static V Cache<K1, K2, K3, K4, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, TimeSpan expiration)
{
return CacheInternal((param1, param2, param3, param4), value, expiration);
}
public static V Cache<K1, K2, K3, K4, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, TimeSpan expiration) =>
Cached<V>.Save(param1, param2, param3, param4, value, expiration);

public static V Cache<K1, K2, K3, K4, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, TimeSpan expiration, uint limit)
{
return CacheInternal((param1, param2, param3, param4), value, expiration, limit);
}
public static V Cache<K1, K2, K3, K4, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, TimeSpan expiration, uint limit) =>
Cached<V>.Save(param1, param2, param3, param4, value, expiration, limit);

public static V Cache<K1, K2, K3, K4, K5, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, TimeSpan expiration)
{
return CacheInternal((param1, param2, param3, param4, param5), value, expiration);
}
public static V Cache<K1, K2, K3, K4, K5, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, TimeSpan expiration) =>
Cached<V>.Save(param1, param2, param3, param4, param5, value, expiration);

public static V Cache<K1, K2, K3, K4, K5, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, TimeSpan expiration, uint limit)
{
return CacheInternal((param1, param2, param3, param4, param5), value, expiration, limit);
}
public static V Cache<K1, K2, K3, K4, K5, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, TimeSpan expiration, uint limit) =>
Cached<V>.Save(param1, param2, param3, param4, param5, value, expiration, limit);

public static V Cache<K1, K2, K3, K4, K5, K6, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, K6 param6, TimeSpan expiration)
{
return CacheInternal((param1, param2, param3, param4, param5, param6), value, expiration);
}
public static V Cache<K1, K2, K3, K4, K5, K6, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, K6 param6, TimeSpan expiration) =>
Cached<V>.Save(param1, param2, param3, param4, param5, param6, value, expiration);

public static V Cache<K1, K2, K3, K4, K5, K6, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, K6 param6, TimeSpan expiration, uint limit)
{
return CacheInternal((param1, param2, param3, param4, param5, param6), value, expiration, limit);
}
public static V Cache<K1, K2, K3, K4, K5, K6, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, K6 param6, TimeSpan expiration, uint limit) =>
Cached<V>.Save(param1, param2, param3, param4, param5, param6, value, expiration, limit);

public static V Cache<K1, K2, K3, K4, K5, K6, K7, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, K6 param6, K7 param7, TimeSpan expiration)
{
return CacheInternal((param1, param2, param3, param4, param5, param6, param7), value, expiration);
}
public static V Cache<K1, K2, K3, K4, K5, K6, K7, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, K6 param6, K7 param7, TimeSpan expiration) =>
Cached<V>.Save(param1, param2, param3, param4, param5, param6, param7, value, expiration);

public static V Cache<K1, K2, K3, K4, K5, K6, K7, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, K6 param6, K7 param7, TimeSpan expiration, uint limit)
{
return CacheInternal((param1, param2, param3, param4, param5, param6, param7), value, expiration, limit);
}
public static V Cache<K1, K2, K3, K4, K5, K6, K7, V>(this V value, K1 param1, K2 param2, K3 param3, K4 param4, K5 param5, K6 param6, K7 param7, TimeSpan expiration, uint limit) =>
Cached<V>.Save(param1, param2, param3, param4, param5, param6, param7, value, expiration, limit);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static V CacheInternal<K, V>(K key, V value, TimeSpan expiration) where K : notnull
{
return new Cached<K, V>(key, default!, found: false).Save(value, expiration);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static V CacheInternal<K, V>(K key, V value, TimeSpan expiration, uint limit) where K : notnull
{
return new Cached<K, V>(key, default!, found: false).Save(value, expiration, limit);
}
}

0 comments on commit 7f2c021

Please sign in to comment.