Skip to content

Instantly share code, notes, and snippets.

@pknam
Last active January 18, 2016 09:10
Show Gist options
  • Save pknam/98466ec459179796da05 to your computer and use it in GitHub Desktop.
Save pknam/98466ec459179796da05 to your computer and use it in GitHub Desktop.
Memory Cache sample code
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