Exemplo n.º 1
0
        /// <summary>
        /// Clears the specified caches for only the indices passed under indices
        /// </summary>
        public IIndicesResponse ClearCache(IEnumerable <string> indices, ClearCacheOptions options)
        {
            string path = "/_cache/clear";

            if (indices != null && indices.Any(s => !string.IsNullOrEmpty(s)))
            {
                indices = indices.Where(s => !string.IsNullOrEmpty(s));
                path    = this.PathResolver.CreateIndexPath(indices) + path;
            }
            if (options != ClearCacheOptions.All)
            {
                var caches = new List <string>();
                if ((options & ClearCacheOptions.Id) == ClearCacheOptions.Id)
                {
                    caches.Add("id=true");
                }
                if ((options & ClearCacheOptions.Filter) == ClearCacheOptions.Filter)
                {
                    caches.Add("filter=true");
                }
                if ((options & ClearCacheOptions.FieldData) == ClearCacheOptions.FieldData)
                {
                    caches.Add("field_data=true");
                }
                if ((options & ClearCacheOptions.Bloom) == ClearCacheOptions.Bloom)
                {
                    caches.Add("bloom=true");
                }

                path += "?" + string.Join("&", caches.ToArray());
            }

            ConnectionStatus status = this.Connection.PostSync(path, string.Empty);
            var response            = new IndicesResponse();

            try
            {
                response         = this.Deserialize <IndicesResponse>(status.Result);
                response.IsValid = true;
            }
            catch
            {
            }
            response.ConnectionStatus = status;
            return(response);
        }
Exemplo n.º 2
0
        public IndicesResponse ClearCache(List <string> indices, ClearCacheOptions options)
        {
            var path = "/_cache/clear";

            if (indices != null && indices.Any(s => !string.IsNullOrEmpty(s)))
            {
                path = "/" + string.Join(",", indices.Where(s => !string.IsNullOrEmpty(s)).ToArray()) + path;
            }
            if (options != null && options != ClearCacheOptions.All)
            {
                var caches = new List <string>();
                if ((options & ClearCacheOptions.Id) == ClearCacheOptions.Id)
                {
                    caches.Add("id=true");
                }
                if ((options & ClearCacheOptions.Filter) == ClearCacheOptions.Filter)
                {
                    caches.Add("filter=true");
                }
                if ((options & ClearCacheOptions.FieldData) == ClearCacheOptions.FieldData)
                {
                    caches.Add("field_data=true");
                }
                if ((options & ClearCacheOptions.Bloom) == ClearCacheOptions.Bloom)
                {
                    caches.Add("bloom=true");
                }

                path += "?" + string.Join("&", caches.ToArray());
            }

            var status   = this.Connection.PostSync(path, string.Empty);
            var response = new IndicesResponse();

            try
            {
                response = JsonConvert.DeserializeObject <IndicesResponse>(status.Result);
            }
            catch {}
            response.ConnectionStatus = status;
            return(response);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Clears the browser cache
        /// <para>No windows should be attached to the framework agent</para>
        /// <para>Any browsers not attached to the framework agent of the same type as browserType will be closed</para>
        /// </summary>
        /// <param name="browserType">The browser type that will have its cache cleared</param>
        /// <param name="options">The cached items to be cleared</param>
        public static void ClearCache(string browserType, ClearCacheOptions options = ClearCacheOptions.CachedFiles | ClearCacheOptions.Cookies)
        {
            if (Agent == null)
            {
                InitializeAgent(ParseBrowserType(browserType));
            }
            else if (Agent.GetAttachedBrowserWindows().Length > 0)
            {
                throw new Exception(string.Format("Current framework agent has {0} attached windows."
                                                  + " All browser windows of type {1} must be closed before cache can be cleared.",
                                                  Agent.GetAttachedBrowserWindows().Length, Agent.BrowserType));
            }

            // Close all browser windows that may not be attached to this agent before flushing the cache
            // The file system gets a permission error if any browser windows are still open when trying to delete the cache
            Agent.CloseAllBrowserWindows();
            Agent.ClearBrowserCache(options);

            // Logger.Instance.LogInfo("Clearing browser cache in browser: " + browserType);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Clears the specified caches for all indices
 /// </summary>
 public IIndicesResponse ClearCache(ClearCacheOptions options)
 {
     return(this.ClearCache(null, options));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Clears the specified caches for the default index set in the client settings
 /// </summary>
 public IIndicesResponse ClearCache <T>(ClearCacheOptions options) where T : class
 {
     return(this.ClearCache(new List <string> {
         this.IndexNameResolver.GetIndexForType <T>()
     }, options));
 }
Exemplo n.º 6
0
 public IndicesResponse ClearCache <T>(ClearCacheOptions options) where T : class
 {
     return(this.ClearCache(new List <string> {
         this.Settings.DefaultIndex
     }, options));
 }