Exemplo n.º 1
0
 private void CheckCache(bool forced = false)
 {
     if (!_initialized)
     {
         Initialize();
         _initialized = true;
     }
     if (string.IsNullOrWhiteSpace(_file))
     {
         Setup();
         if (File.Exists(ResolvedFilePath))
         {
             _file = ResolvedFilePath;
         }
         else
         {
             return;
         }
     }
     if (forced || LastCheck.AddMilliseconds(CheckRate) < DateTime.Now)
     {
         if (File.GetLastWriteTime(_file) > LastFileTime)
         {
             _cache.Clear();
             Initialize();
         }
         LastCheck = DateTime.Now;
     }
 }
Exemplo n.º 2
0
        private void CheckCache(bool forced = false)
        {
            if (!_initialized)
            {
                Initialize();
                _initialized = true;
            }
            if (!forced && EsClient.InvalidConnection)
            {
                if (EsClient.LastPing.AddMilliseconds(PingRate) > DateTime.Now)
                {
                    return;
                }
            }
            if (!forced && LastCheck.AddMilliseconds(CacheRate) > DateTime.Now)
            {
                return;
            }
            var currentETag    = ETag;
            var currentVersion = Version;
            var url            = GetBaseUrl() + "_search?search_type=count";
            var query          = leasequery;
            var json           = EsClient.ExecuteCommand(url, query);

            if (null == json)
            {
                ETag      = null;
                Version   = DateTime.MinValue;
                LastCheck = DateTime.MinValue;
            }
            else
            {
                var j = json.jsonify();
                ETag    = j.str("aggregations._version.value");
                Version = j.date("aggregations._timestamp.value_as_string");
            }
            if (ETag != currentETag || Version != currentVersion)
            {
                _cache.Clear();
            }
        }