namespace Quadarax.Foundation.Common.Cache
{
    public abstract class Cache<TKey, TValue>
    {
        public bool Enabled { get; set; }

        public TValue this[TKey key]
        {
            get
            {
                if (!this.Enabled)
                    return default(TValue);
                return this.GetValue(key);
            }
            set
            {
                if (!this.Enabled)
                    return;
                this.SetValue(key, value);
            }
        }

        public bool Remove(TKey key)
        {
            if (!this.Enabled)
                return false;
            return this.RemoveByKey(key);
        }

        public abstract bool Invalidate(TKey key);

        protected abstract TValue GetValue(TKey key);

        protected abstract void SetValue(TKey key, TValue value);

        protected abstract bool RemoveByKey(TKey key);
    }
}