-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringCacher.cs
67 lines (55 loc) · 1.65 KB
/
StringCacher.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Caching;
namespace MuntersGIPHY
{
public class CacheGiphy
{
static ObjectCache cache = MemoryCache.Default;
public string GetOrCreate(string word)
{
string fileContents = (string) cache.Get(word);
if (!string.IsNullOrEmpty(fileContents))
{
CacheItemPolicy policy = new CacheItemPolicy();
//List<string> filePaths = new List<string>();
//filePaths.Add("c:\\cache\\example.txt");
//policy.ChangeMonitors.Add(new
// HostFileChangeMonitor(filePaths));
cache.Set("fileCon", word, policy);
return word;
}
else
{
return word;
}
}
}
}
//using System.Collections.Generic;
//using Microsoft.Extensions.Caching.Memory;
//namespace MuntersGIPHY
//{
// public class StringCacher
// {
// private IMemoryCache _cache;
// public readonly Dictionary<string, string> StringCache;
// public StringCacher()
// {
// _cache = memoryCache;
// }
// public string AddOrReuse(string stringToCache)
// {
// if (StringCache.ContainsKey(stringToCache))
// {
// StringCache[stringToCache] = stringToCache;
// }
// else
// {
// return stringToCache;
// }
// return StringCache[stringToCache];
// }
// }
//}