This commit is contained in:
Drechsler, Meik
2025-08-14 16:20:42 +02:00
parent fb150ac204
commit 3a001d0e55
33 changed files with 2405 additions and 0 deletions

60
C4IT.API/ApiCache.cs Normal file
View File

@@ -0,0 +1,60 @@
using System;
using System.Runtime.Caching;
using System.Linq;
using System.Collections.Generic;
namespace C4IT.API
{
class ApiCache
{
public static object GetValue(string key)
{
MemoryCache memoryCache = MemoryCache.Default;
return memoryCache.Get(key);
}
public static object AddOrGet(string key, object value, DateTimeOffset absExpiration)
{
MemoryCache memoryCache = MemoryCache.Default;
lock (memoryCache)
{
return memoryCache.AddOrGetExisting(key, value, absExpiration);
}
}
public static bool Add(string key, object value, DateTimeOffset absExpiration)
{
MemoryCache memoryCache = MemoryCache.Default;
lock (memoryCache)
{
return memoryCache.Add(key, value, absExpiration);
}
}
public static void Delete(string key)
{
MemoryCache memoryCache = MemoryCache.Default;
if (memoryCache.Contains(key))
{
memoryCache.Remove(key);
}
}
public static List<String> GetAllKeysInCache()
{
MemoryCache memoryCache = MemoryCache.Default;
List<String> cacheKeys = new List<String>();
var keys= memoryCache.Where(o => true).Select(o => o.Key);
foreach (var key in keys)
{
cacheKeys.Add(key);
}
return cacheKeys;
}
}
}