Cache.cs 914 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. namespace Quadarax.Foundation.Common.Cache
  2. {
  3. public abstract class Cache<TKey, TValue>
  4. {
  5. public bool Enabled { get; set; }
  6. public TValue this[TKey key]
  7. {
  8. get
  9. {
  10. if (!this.Enabled)
  11. return default(TValue);
  12. return this.GetValue(key);
  13. }
  14. set
  15. {
  16. if (!this.Enabled)
  17. return;
  18. this.SetValue(key, value);
  19. }
  20. }
  21. public bool Remove(TKey key)
  22. {
  23. if (!this.Enabled)
  24. return false;
  25. return this.RemoveByKey(key);
  26. }
  27. public abstract bool Invalidate(TKey key);
  28. protected abstract TValue GetValue(TKey key);
  29. protected abstract void SetValue(TKey key, TValue value);
  30. protected abstract bool RemoveByKey(TKey key);
  31. }
  32. }