private void btnGet_Click(object sender, EventArgs e) { ObjectCache cache = MemoryCache.Default; string fileContents = cache["filecontents"] as string; if (fileContents == null) { CacheItemPolicy policy = new CacheItemPolicy(); List<string> filePaths = new List<string>(); filePaths.Add("c:\\cache\\example.txt"); policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths)); // Fetch the file contents. fileContents = File.ReadAllText("c:\\cache\\example.txt"); cache.Set("filecontents", fileContents, policy); } Label1.Text = fileContents; }
Source : https://msdn.microsoft.com/en-us/library/system.runtime.caching.memorycache(v=vs.110).aspx
'C#(CSharp) > Etc' 카테고리의 다른 글
C# memory cache logic (0) | 2018.05.31 |
---|---|
Write exception log in File. (0) | 2018.05.29 |
Deleting multiple files with wildcard (0) | 2018.05.17 |
How to crop an image using C#? (0) | 2018.05.09 |
Get utc time to time zone standard time (0) | 2018.04.09 |