49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Sockeye.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 Clear()
|
|
{
|
|
_cache.Clear();
|
|
}
|
|
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 |