Skip to content

Commit

Permalink
Fixing the minimum cache timeout validation #159 (it is too early...)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaCo committed Jun 5, 2017
1 parent 31e9e7b commit c7956bc
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/CacheManager.StackExchange.Redis/RedisCacheHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,8 @@ public override UpdateItemResult<TCacheValue> Update(string key, string region,
{
return UpdateItemResult.ForItemDidNotExist<TCacheValue>();
}
if (item.ExpirationTimeout < MinimumExpirationTimeout)
{
throw new ArgumentException("Timeout lower than one millisecond is not supported.", nameof(item.ExpirationTimeout));
}

ValidateExpirationTimeout(item);

// run update
var newValue = updateValue(item.Value);
Expand Down Expand Up @@ -357,10 +355,8 @@ protected UpdateItemResult<TCacheValue> UpdateNoScript(string key, string region
{
return UpdateItemResult.ForItemDidNotExist<TCacheValue>();
}
if (item.ExpirationTimeout < MinimumExpirationTimeout)
{
throw new ArgumentException("Timeout lower than one millisecond is not supported.", nameof(item.ExpirationTimeout));
}

ValidateExpirationTimeout(item);

var oldValue = ToRedisValue(item.Value);

Expand Down Expand Up @@ -754,6 +750,14 @@ private static Tuple<string, string> ParseKey(string value)
return Tuple.Create(key, region);
}

private static void ValidateExpirationTimeout(CacheItem<TCacheValue> item)
{
if ((item.ExpirationMode == ExpirationMode.Absolute || item.ExpirationMode == ExpirationMode.Sliding) && item.ExpirationTimeout < MinimumExpirationTimeout)
{
throw new ArgumentException("Timeout lower than one millisecond is not supported.", nameof(item.ExpirationTimeout));
}
}

private string GetKey(string key, string region = null)
{
if (string.IsNullOrWhiteSpace(key))
Expand Down Expand Up @@ -833,10 +837,7 @@ private bool Set(CacheItem<TCacheValue> item, When when, bool sync = false)

var flags = sync ? CommandFlags.None : CommandFlags.FireAndForget;

if (item.ExpirationTimeout < MinimumExpirationTimeout)
{
throw new ArgumentException("Timeout lower than one millisecond is not supported.", nameof(item.ExpirationTimeout));
}
ValidateExpirationTimeout(item);

// ARGV [1]: value, [2]: type, [3]: expirationMode, [4]: expirationTimeout(millis), [5]: created(ticks)
var parameters = new RedisValue[]
Expand Down Expand Up @@ -916,10 +917,7 @@ private bool SetNoScript(CacheItem<TCacheValue> item, When when, bool sync = fal
var fullKey = GetKey(item.Key, item.Region);
var value = ToRedisValue(item.Value);

if (item.ExpirationTimeout < MinimumExpirationTimeout)
{
throw new ArgumentException("Timeout lower than one millisecond is not supported.", nameof(item.ExpirationTimeout));
}
ValidateExpirationTimeout(item);

var metaValues = new[]
{
Expand Down

0 comments on commit c7956bc

Please sign in to comment.