This commit is contained in:
2021-12-22 22:57:58 +00:00
parent 7fe8ba9a3d
commit 4d40acff6c
2 changed files with 74 additions and 3 deletions

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
namespace AyaNova.Util
{
//Object cache - used by biz objects during get report data to temporarily cache values from database for single request
//saves db calls and formatting
internal class ObjectCache
{
private Dictionary<string, object> _cache = new Dictionary<string, object>();
// internal ObjectCache()
// {
// System.Diagnostics.Debug.WriteLine("constructing objectcache");
// }
internal void Add(object value, string key, long? id = 0)
{
_cache[$"{key}{id}"] = value;
// System.Diagnostics.Debug.WriteLine($"ADD {key}{id} - {value}");
}
internal object Get(string key, long? id = 0)
{
object value = null;
if (_cache.TryGetValue($"{key}{id}", out value))
{
//System.Diagnostics.Debug.WriteLine($"get cache hit {key}{id}");
return value;
}
else
{
//System.Diagnostics.Debug.WriteLine($"get cache miss {key}{id}");
return null;
}
}
internal bool Has(string key, long? id = 0)
{
return _cache.ContainsKey($"{key}{id}");
}
}//eoc
}//eons