public void Insert(string key, byte[] value, TimeSpan expiration)
 {
     try
     {
         var expireData = new ExpirationData(expiration);
         if (value == null)
         {
             if (IgnoreNullValues)
             {
                 return;
             }
             else
             {
                 value = nullStringBytes;
             }
         }
         lock (syncObj)
         {
             //Remove(key);
             Logger.Debug("V20.BinaryFillCacheProvider saving into " + GetFullPath(key));
             System.IO.File.WriteAllBytes(GetFullPath(key), value);
         }
     }
     catch (Exception e)
     {
         Logger.Error("V20.BinaryFillCacheProvider error saving into " + GetFullPath(key), e);
     }
 }
 public T Get(string key)
 {
     if (internalValue == default(T))
     {
         internalValue = Deserialize <T>(System.IO.File.ReadAllBytes(GetFullPath(key, true)));
         ExpirationData expireData = Deserialize <ExpirationData>(System.IO.File.ReadAllBytes(GetFullPath(key, false)));
         internalValueCreated = expireData.Created();
     }
     return(internalValue);
 }
        public bool Exists(string key)
        {
            if (!System.IO.File.Exists(GetFullPath(key, false)))
            {
                System.Threading.Thread.Sleep(200);
                if (!System.IO.File.Exists(GetFullPath(key, false)))
                {
                    Logger.Debug($"Exist func: no {GetFullPath(key, false)}");
                    return(false);
                }
            }
            if (!System.IO.File.Exists(GetFullPath(key, true)))
            {
                Logger.Debug($"Exist func: no {GetFullPath(key, true)}");
                return(false);
            }



            try
            {
                ExpirationData expireData = Deserialize <ExpirationData>(System.IO.File.ReadAllBytes(GetFullPath(key, false)));
                if (expireData == default(ExpirationData))
                {
                    Logger.Debug($"Exist func: no expiration data: " + Newtonsoft.Json.JsonConvert.SerializeObject(expireData));
                    return(false);
                }

                if (expireData.ExpirationInTicks == ExpirationData.UnlimitedExpiration.Ticks)
                {
                    return(true);
                }

                bool stillValid = expireData.ExpiresAt() > DateTime.UtcNow;
                if (!stillValid)
                {
                    Logger.Debug($"Exist func: expired data: " + Newtonsoft.Json.JsonConvert.SerializeObject(expireData));
                    return(false);
                }
                if (expireData.Created() != internalValueCreated)
                {
                    internalValue = default(T);
                }
                return(stillValid);
            }
            catch (Exception e)
            {
                Logger.Debug("V20.FillCacheProvider Exists error for key " + key, e);
                //Remove(key);
                return(false);
            }
        }
        public void Insert(string key, T value, TimeSpan expiration)
        {
            try
            {
                var expireData = new ExpirationData(expiration);

                lock (syncObj)
                {
                    //Remove(key);
                    Logger.Debug("V20.FillCacheProvider saving into " + GetFullPath(key, true));
                    System.IO.File.WriteAllBytes(GetFullPath(key, true), Serialize <T>(value));
                    Logger.Debug("V20.FillCacheProvider saving into " + GetFullPath(key, false));
                    System.IO.File.WriteAllBytes(GetFullPath(key, false), Serialize <ExpirationData>(expireData));

                    internalValue        = value;
                    internalValueCreated = expireData.Created();
                }
            }
            catch (Exception e)
            {
                Logger.Error("V20.FillCacheProvider error saving into " + GetFullPath(key, true), e);
            }
        }