Ejemplo n.º 1
0
        private bool _Set(Areas area, string field, string key, string value, TimeSpan expiration)
        {
            key = EncodeBlobName(key);

            string _value = null;

            /* if the string is over 250K in length (approximately 500K in size) then compress it for performance */
            if (value.Length > 1024 * 250)
            {
                _value = Compression.Compress(value);
            }
            else
            {
                _value = value;
            }

            var blob = GetBlobReference(area, field, key);

            VigilCacheData data           = new VigilCacheData(_value, expiration);
            var            serializedData = JsonConvert.SerializeObject(data);

            blob.UploadText(serializedData);

            return(true);
        }
Ejemplo n.º 2
0
        private string _Get(Areas area, string field, string key)
        {
            key = EncodeBlobName(key);

            var blob = GetBlobReference(area, field, key);

            if (!blob.Exists())
            {
                return(null);
            }

            var            tmp = blob.DownloadText();
            VigilCacheData vcd = VigilCacheData.FromString(tmp);

            if (vcd.ExpirationDate < DateTime.UtcNow)
            {
                blob.Delete();
                return(null);
            }

            string result = null;

            if (Compression.IsBase64String(tmp))
            {
                result = Compression.Decompress(vcd.Value);
            }
            else
            {
                result = vcd.Value;
            }

            return(result);
        }
Ejemplo n.º 3
0
        private string _Get(Areas area, string field, string key)
        {
            key = EncodeBlobName(key);
            var       redisKey = string.Format("{0}^{1}^{2}", area.ToString(), field, key);
            IDatabase cache    = lazyConnection.Value.GetDatabase();

            if (cache.KeyExists(redisKey))
            {
                var            tmp = cache.StringGet(redisKey);
                VigilCacheData vcd = VigilCacheData.FromString(tmp);

                if (vcd != null && vcd.ExpirationDate < DateTime.UtcNow)
                {
                    cache.KeyDelete(redisKey);
                    return(null);
                }

                string result = null;
                if (Compression.IsBase64String(tmp))
                {
                    result = Compression.Decompress(vcd.Value);
                }
                else
                {
                    result = vcd.Value;
                }
                return(result);
            }

            return(null);
        }
Ejemplo n.º 4
0
        private bool _Set(Areas area, string field, string key, string value, TimeSpan expiration)
        {
            key = EncodeBlobName(key);

            string _value = null;

            /* if the string is over 250K in length (approximately 500K in size) then compress it for performance */
            if (value.Length > 1024 * 250)
            {
                _value = Compression.Compress(value);
            }
            else
            {
                _value = value;
            }

            var       redisKey = string.Format("{0}^{1}^{2}", area.ToString(), field, key);
            IDatabase cache    = lazyConnection.Value.GetDatabase();

            VigilCacheData data           = new VigilCacheData(_value, expiration);
            var            serializedData = JsonConvert.SerializeObject(data);

            cache.StringSet(redisKey, serializedData, expiration);
            return(true);
        }
Ejemplo n.º 5
0
        private T _Get <T>(Areas area, string field, string key)
        {
            key = EncodeBlobName(key);

            var blob = GetBlobReference(area, field, key);

            if (!blob.Exists())
            {
                return(default(T));
            }

            string json = "";

            try
            {
                var            tmp = blob.DownloadText();
                VigilCacheData vcd = VigilCacheData.FromString(tmp);

                if (vcd.ExpirationDate < DateTime.UtcNow)
                {
                    blob.Delete();
                    return(default(T));
                }

                if (Compression.IsBase64String(vcd.Value))
                {
                    json = Compression.Decompress(vcd.Value);
                }
                else
                {
                    json = vcd.Value;
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Could not retrieve cache object for key {0}. {1}", key, ex.Message);
                return(default(T));
            }

            if (!string.IsNullOrEmpty(json))
            {
                try
                {
                    return(JsonConvert.DeserializeObject <T>(json));
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Could not deserialize cache object for key {0}. {1}", key, ex.Message);
                }
            }

            return(default(T));
        }
Ejemplo n.º 6
0
        private T _Get <T>(Areas area, string field, string key)
        {
            key = EncodeBlobName(key);
            var       redisKey = string.Format("{0}^{1}^{2}", area.ToString(), field, key);
            IDatabase cache    = lazyConnection.Value.GetDatabase();
            string    json     = "";

            if (cache.KeyExists(redisKey))
            {
                var            tmp = cache.StringGet(redisKey);
                VigilCacheData vcd = VigilCacheData.FromString(tmp);

                if (vcd == null || vcd.ExpirationDate < DateTime.UtcNow)
                {
                    cache.KeyDelete(redisKey);
                    return(default(T));;
                }

                if (Compression.IsBase64String(vcd.Value))
                {
                    json = Compression.Decompress(vcd.Value);
                }
                else
                {
                    json = vcd.Value;
                }
            }

            if (!string.IsNullOrEmpty(json))
            {
                try
                {
                    return(JsonConvert.DeserializeObject <T>(json));
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Could not deserialize cache object for key {0}. {1}", key, ex.Message);
                }
            }

            return(default(T));
        }