Created
December 23, 2019 09:15
-
-
Save peterrydetorp/3df909f32b8eb065a55cf06f0e096e43 to your computer and use it in GitHub Desktop.
HasPersonalizationCacheManager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } | |
| } | |
Author
Hi
It should return ”result”, thanks for the heads up.
/Peter
Sent from my iPhone therefore somewhat brief.
25 dec. 2019 kl. 16:37 skrev Michael <notifications@github.com<mailto:notifications@github.com>>:
Line 14 should return true if the cache contains the key, right? Looks like this always returns false.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<https://gist.github.com/3df909f32b8eb065a55cf06f0e096e43?email_source=notifications&email_token=AFIY3G3O7DHUS2ZYXPEH2XDQ2N43HA5CNFSM4J7FPCV2YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAF6OYI#gistcomment-3120516>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AFIY3G4X7HOLFLY5OVPWWX3Q2N43HANCNFSM4J7FPCVQ>.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 14 should return true if the cache contains the key, right? Looks like this always returns false.