Skip to content

Commit 93ced0e

Browse files
committed
Fixed a bug in the cachers, they returned the cached object ONLY if the object in the cache was 20 minutes old or more, the right thing to do is to return that object if it's 20 minutes or less old
1 parent 4c126c0 commit 93ced0e

4 files changed

Lines changed: 12 additions & 3 deletions

File tree

Plugins/CacheProviders/ApplicationCacher/ApplicationCacher.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public T Get<T> (string Name, int CacheDurationInMinutes)
3434
if (cached == null)
3535
return null;
3636

37-
return cached.When.AddMinutes(CacheDurationInMinutes) > DateTime.Now ? null : cached.Cached;
37+
if (cached.When.AddMinutes(CacheDurationInMinutes) < DateTime.Now)
38+
return null;
39+
40+
return cached.Cached;
3841
}
3942

4043

Plugins/CacheProviders/BasicCacher/BasicCacher.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ public T Get<T>(string Name, int CacheDurationInMinutes) where T : class
2626
if (!_cache.ContainsKey(CachePrefix + Name)) return null;
2727
var cached = _cache[CachePrefix + Name] as CachedObject<T>;
2828
if (cached == null) return null;
29-
if (cached.When.AddMinutes(CacheDurationInMinutes) > DateTime.Now)
29+
30+
if (cached.When.AddMinutes(CacheDurationInMinutes) < DateTime.Now)
3031
return null;
32+
3133
return cached.Cached;
3234
}
3335

Plugins/CacheProviders/WebCache/WebCacher.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ public T Get<T>(string Name, int CacheDurationInMinutes)
3232
var cached = _Cache[CachePrefix + Name] as CachedObject<T>;
3333
if (cached == null)
3434
return null;
35-
if (cached.When.AddMinutes(CacheDurationInMinutes) > DateTime.Now)
35+
36+
if (cached.When.AddMinutes(CacheDurationInMinutes) < DateTime.Now)
3637
return null;
38+
3739
return cached.Cached;
3840
}
3941

Samples/ConsoleSample/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ static void Main()
1111
var user = new User(new BasicCacher.BasicCacher(), new SimpleLogProvider());
1212
var u = user.Get("rumpl");
1313
Console.WriteLine(u.Blog);
14+
u = user.Get("rumpl");
15+
Console.WriteLine(u.Blog);
1416
}
1517
}
1618
}

0 commit comments

Comments
 (0)