Last active
January 18, 2016 09:10
-
-
Save pknam/98466ec459179796da05 to your computer and use it in GitHub Desktop.
Memory Cache sample code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.Caching; | |
using System.Threading; | |
namespace cache_test | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
MemoryCache cache = MemoryCache.Default; | |
// expire after 5 sec | |
cache.Set("hi", 444, DateTimeOffset.Now.AddSeconds(5)); | |
while (true) | |
{ | |
object val = cache.Get("hi"); | |
if (val == null) | |
Console.WriteLine("cache miss"); | |
else | |
Console.WriteLine("cache : {0}", val); | |
Thread.Sleep(1000); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment