Skip to content

Instantly share code, notes, and snippets.

@peterrydetorp
Created December 23, 2019 09:15
Show Gist options
  • Select an option

  • Save peterrydetorp/3df909f32b8eb065a55cf06f0e096e43 to your computer and use it in GitHub Desktop.

Select an option

Save peterrydetorp/3df909f32b8eb065a55cf06f0e096e43 to your computer and use it in GitHub Desktop.
HasPersonalizationCacheManager
public class HasPersonalizationCacheManager
{
private static readonly HasPersonalizationCache Cache = new HasPersonalizationCache();
public static bool TryGet(Item item, out bool result)
{
result = false;
var key = GetKey(item);
if (Cache.InnerCache.ContainsKey(key))
{
var nullableBool = Cache.InnerCache.GetValue(key) as bool?;
result = nullableBool.Value;
}
return false;
}
private static string GetKey(Item item)
{
return $"{item.ID}_{item.Language.Name}";
}
public static void Set(Item item, bool value)
{
Cache.AddCacheObject(GetKey(item), value);
}
public void ClearCache(object sender, EventArgs args)
{
Cache.Clear();
}
}
class HasPersonalizationCache : CustomCache
{
internal HasPersonalizationCache() : base("Dometic.Website.Components.EdgeCache.HasPersonalizationCache", StringUtil.ParseSizeString("1MB"))
{ }
internal void AddCacheObject(string key, object value)
{
InnerCache.Add(key, value);
}
internal object GetCacheObject(string key)
{
if (!InnerCache.ContainsKey(key)) return null;
return InnerCache.GetValue(key);
}
}
@michaellwest
Copy link

Line 14 should return true if the cache contains the key, right? Looks like this always returns false.

@peterrydetorp
Copy link
Author

peterrydetorp commented Dec 25, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment