Skip to content

Commit 2d0214e

Browse files
authored
Merge pull request #93 from cnblogs/hotfix/computing-expiration
Change computing expiration to work with memcached 1.4
2 parents f435322 + 83cc442 commit 2d0214e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Enyim.Caching/MemcachedClient.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,22 @@ private void StartPool()
9090

9191
public void Add(string key, object value, int cacheSeconds)
9292
{
93-
Store(StoreMode.Add, key, value, new TimeSpan(0, 0, cacheSeconds));
93+
Store(StoreMode.Add, key, value, TimeSpan.FromSeconds(cacheSeconds));
9494
}
9595

9696
public async Task AddAsync(string key, object value, int cacheSeconds)
9797
{
98-
await StoreAsync(StoreMode.Add, key, value, new TimeSpan(0, 0, cacheSeconds));
98+
await StoreAsync(StoreMode.Add, key, value, TimeSpan.FromSeconds(cacheSeconds));
9999
}
100100

101101
public void Set(string key, object value, int cacheSeconds)
102102
{
103-
Store(StoreMode.Set, key, value, new TimeSpan(0, 0, cacheSeconds));
103+
Store(StoreMode.Set, key, value, TimeSpan.FromSeconds(cacheSeconds));
104104
}
105105

106106
public async Task SetAsync(string key, object value, int cacheSeconds)
107107
{
108-
await StoreAsync(StoreMode.Set, key, value, new TimeSpan(0, 0, cacheSeconds));
108+
await StoreAsync(StoreMode.Set, key, value, TimeSpan.FromSeconds(cacheSeconds));
109109
}
110110

111111
/// <summary>
@@ -1161,6 +1161,11 @@ protected static uint GetExpiration(
11611161
// infinity
11621162
if (validFor == TimeSpan.Zero || validFor == TimeSpan.MaxValue) return 0;
11631163

1164+
if (validFor.Value.TotalSeconds <= MaxSeconds)
1165+
{
1166+
return (uint)validFor.Value.TotalSeconds;
1167+
}
1168+
11641169
expiresAt = DateTime.Now.Add(validFor.Value);
11651170
}
11661171

0 commit comments

Comments
 (0)