From 37bc610c38c0c5996f392be4e592d5726f97f7ff Mon Sep 17 00:00:00 2001 From: ClemensFischer Date: Mon, 5 Feb 2024 16:33:14 +0100 Subject: [PATCH] Update FileDbCache.cs --- Caches/FileDbCache/FileDbCache.cs | 49 +++++++++++++++++-------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/Caches/FileDbCache/FileDbCache.cs b/Caches/FileDbCache/FileDbCache.cs index ebba509b..8b292d51 100644 --- a/Caches/FileDbCache/FileDbCache.cs +++ b/Caches/FileDbCache/FileDbCache.cs @@ -83,10 +83,7 @@ namespace MapControl.Caching public byte[] Get(string key) { - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentException($"The {nameof(key)} argument must not be null or empty.", nameof(key)); - } + CheckArgument(key); byte[] value = null; @@ -116,20 +113,7 @@ namespace MapControl.Caching public void Set(string key, byte[] value, DistributedCacheEntryOptions options) { - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentException($"The {nameof(key)} argument must not be null or empty.", nameof(key)); - } - - if (value == null) - { - throw new ArgumentNullException($"The {nameof(value)} argument must not be null.", nameof(value)); - } - - if (options == null) - { - throw new ArgumentNullException($"The {nameof(options)} argument must not be null.", nameof(options)); - } + CheckArguments(key, value, options); DateTime expiration; @@ -176,14 +160,12 @@ namespace MapControl.Caching public void Refresh(string key) { + CheckArgument(key); } public void Remove(string key) { - if (string.IsNullOrEmpty(key)) - { - throw new ArgumentException($"The {nameof(key)} argument must not be null or empty.", nameof(key)); - } + CheckArgument(key); try { @@ -217,5 +199,28 @@ namespace MapControl.Caching Remove(key); return Task.CompletedTask; } + + private static void CheckArgument(string key) + { + if (string.IsNullOrEmpty(key)) + { + throw new ArgumentException($"The {nameof(key)} argument must not be null or empty.", nameof(key)); + } + } + + private static void CheckArguments(string key, byte[] value, DistributedCacheEntryOptions options) + { + CheckArgument(key); + + if (value == null) + { + throw new ArgumentNullException($"The {nameof(value)} argument must not be null.", nameof(value)); + } + + if (options == null) + { + throw new ArgumentNullException($"The {nameof(options)} argument must not be null.", nameof(options)); + } + } } }