Added DeleteCacheKey method to TMVCCacheController (#731)

Deletes the specified key(s) from the Redis cache. Pattern matching can be used to delete multiple keys
This commit is contained in:
Graham Murt 2024-02-21 22:33:25 +00:00 committed by GitHub
parent cc5789d56e
commit 0ceb7180fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -80,6 +80,10 @@ type
/// </summary>
procedure SetCacheKey(const AKey: string);
/// <summary>
/// Deletes the specified key(s) from the redis cache. Pattern matching can be used to delete multiple keys
/// </summary>
procedure DeleteCacheKey(const AKey: string = '');
/// <summary>
/// Returns true if the cache is available and automatically fills
/// the response using the cache contents
/// </summary>
@ -93,6 +97,7 @@ type
/// retrived from cache
/// </summary>
property ExposeCache: Boolean read FExposeCache write SetExposeCache;
end;
implementation
@ -258,4 +263,22 @@ begin
FExposeCache := AValue;
end;
procedure TMVCCacheController.DeleteCacheKey(const AKey: string = '');
var
AKeys: TArray<string>;
ARedis: IRedisClient;
begin
ARedis := RedisClient;
if AKey <> '' then
begin
AKeys := ARedis.KEYS(AKey).ToArray;
ARedis.DEL(AKeys);
end
else
begin
CheckCacheKey;
ARedis.DEL(FCurrentCacheKey);
end;
end;
end.