68 lines
2.0 KiB
C#
68 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Sockeye.Util
|
|
{
|
|
//Viz 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 VizCache
|
|
{
|
|
private Dictionary<string, string> _vizCache = new Dictionary<string, string>();
|
|
// internal VizCache()
|
|
// {
|
|
// System.Diagnostics.Debug.WriteLine("constructing vizcache");
|
|
// }
|
|
internal void Clear()
|
|
{
|
|
_vizCache.Clear();
|
|
}
|
|
internal void Add(string value, string key, long? id = 0)
|
|
{
|
|
if (value == null) value = string.Empty;
|
|
_vizCache[$"{key}{id}"] = value;
|
|
// System.Diagnostics.Debug.WriteLine($"ADD {key}{id} - {value}");
|
|
}
|
|
internal string Get(string key, long? id = 0)
|
|
{
|
|
string value = null;
|
|
if (_vizCache.TryGetValue($"{key}{id}", out value))
|
|
{
|
|
//System.Diagnostics.Debug.WriteLine($"vizGet cache hit {key}{id}");
|
|
return value;
|
|
}
|
|
else
|
|
{
|
|
//System.Diagnostics.Debug.WriteLine($"vizGet cache miss {key}{id}");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
internal bool Has(string key, long? id = 0)
|
|
{
|
|
return _vizCache.ContainsKey($"{key}{id}");
|
|
}
|
|
|
|
internal bool GetAsBool(string key, long? id = 0)
|
|
{
|
|
var s = Get(key, id);
|
|
if (string.IsNullOrWhiteSpace(s)) return false;
|
|
return bool.Parse(s);
|
|
}
|
|
|
|
internal decimal? GetAsDecimal(string key, long? id = 0)
|
|
{
|
|
var s = Get(key, id);
|
|
if (string.IsNullOrWhiteSpace(s)) return null;
|
|
return decimal.Parse(s);
|
|
}
|
|
|
|
internal long? GetAsLong(string key, long? id = 0)
|
|
{
|
|
var s = Get(key, id);
|
|
if (string.IsNullOrWhiteSpace(s)) return null;
|
|
return long.Parse(s);
|
|
}
|
|
|
|
}//eoc
|
|
|
|
}//eons |