ObjectCache & MemoryCache

public static string GetValue()
{
    const string cacheKey = "CacheKey";
    ObjectCache cache = MemoryCache.Default;
    var cacheValue = cache[cacheKey];
    if (cacheValue == null) // Null value means cache value doesn't exist/expired.
    {
        var value = "Value From External Resource";

        // Create a cache policy that evicts the cache based on the absolute expiration policy.
        var cachePolicy = new CacheItemPolicy
        {
            // Indicates whether a cache entry should be evicted at a specified point in time:
            AbsoluteExpiration = DateTimeOffset.Now.Add(TimeSpan.FromMinutes(60)),
            // Indicates whether a cache entry should be evicted if it has not been accessed in a given span of time:
            SlidingExpiration = TimeSpan.FromMinutes(15)
        };

        // Update the cache based on the policy.
        cache.Set(cacheKey, value, cachePolicy);
    }

    return (string)cacheValue;
}

ObjectCache Methods

HostFileChangeMonitor

public static string GetFileContents()
{
    const string cacheKey = "FileContents";
    ObjectCache cache = MemoryCache.Default;    
    if (cache[cacheKey] == null)
    {
        var filesToMonitor = new List<string>
        {
            "C:\\\\.Directory\\\\FileName1.txt",
            "C:\\\\.Directory\\\\FileName2.txt"
        };        

        // Create a cache policy to monitor a set of files.
        // The policy will evict the cache value when any file changed.
        var cachePolicy = new CacheItemPolicy();
        cachePolicy.ChangeMonitors.Add(new HostFileChangeMonitor(filesToMonitor));

        // Update the cache based on the policy.
				var fileContents = File.ReadAllText(filesToMonitor.First());
        cache.Set(cacheKey, fileContents, cachePolicy);
    }
    return cache.Get(key);
}

SqlDependency