/// <summary>
    /// Renders the particular cache item.
    /// </summary>
    protected void RenderItem(StringBuilder sb, string key, CacheItemContainer container, object value, bool dummy)
    {
        sb.Append("<tr><td class=\"unigrid-actions\">");

        // Get the action
        sb.Append(GetViewAction(key));
        sb.Append(GetDeleteAction(key));
        sb.Append(GetDebugAction(key));

        sb.Append("</td><td><span title=\"" + HTMLHelper.HTMLEncode(key) + "\">");
        string keyTag = TextHelper.LimitLength(key, 100);

        sb.Append(HTMLHelper.HTMLEncode(keyTag));
        sb.Append("</span></td>");

        if (!dummy)
        {
            sb.Append("<td>");

            // Render the value
            if ((value != null) && (value != DBNull.Value))
            {
                sb.Append(HttpUtility.HtmlEncode(DataHelper.GetObjectString(value, 100)));
            }
            else
            {
                sb.Append("null");
            }

            sb.Append("</td>");

            if (CacheDebug.Settings.Enabled)
            {
                // Expiration
                sb.Append("<td>");
                if (container != null)
                {
                    if (container.AbsoluteExpiration != Cache.NoAbsoluteExpiration)
                    {
                        sb.Append(container.AbsoluteExpiration);
                    }
                    else
                    {
                        sb.Append(container.SlidingExpiration);
                    }
                }
                sb.Append("</td>");

                // Expiration
                sb.Append("<td>");
                if (container != null)
                {
                    sb.Append(container.Priority);
                }
                sb.Append("</td>");
            }
        }

        sb.Append("</tr>");
    }
        /// <summary>
        /// Renders the particular cache item.
        /// </summary>
        protected void PrintCacheItemData(DataTable table, string key, CacheItemContainer container, object value)
        {
            if (key.Length > 100)
            {
                key = key.Substring(0, 100);
            }

            int size = 0;
            if ((value != null) && (value != DBNull.Value))
            {
                value = HttpUtility.HtmlEncode(DataHelper.GetObjectString(value, 100, out size));
            }

            object expiration = null;
            object priority = null;

            if (CacheDebug.Settings.Enabled)
            {
                if (container != null)
                {
                    if (container.AbsoluteExpiration != Cache.NoAbsoluteExpiration)
                    {
                        expiration = container.AbsoluteExpiration;
                    }
                    else
                    {
                        expiration = container.SlidingExpiration;
                    }

                    priority = container.Priority;
                }
            }

            table.Rows.Add(key, value, size, expiration, priority);
        }
示例#3
0
            public void InitializeController()
            {
                CacheItemContainer container = CacheItemContainers[Random.Next(0, Count)];

                ContinuousCacheAccessSynchronizationManager.InitializeCacheItemSynchronizationController(container);

                Trace.WriteLine(Name + "Initialized    " + container.CacheKey);
            }
        public void Set(string key, CacheItemContainer data)
        {
            if (isEnabled)
            {
                RedisCache.Set(key, data);
            }

            UpdateCacheItems(key, data);
        }
示例#5
0
            public void IsFetchingData()
            {
                CacheItemContainer container = CacheItemContainers[Random.Next(0, Count)];

                try
                {
                    ContinuousCacheAccessSynchronizationManager.IsFetchingData(container.CacheKey);
                }
                catch (Exception err)
                {
                    Trace.WriteLine(Name + ": NULL REFERENCE FOR    " + container.CacheKey + err.Message);
                }
            }
        public bool TryGetValue <T>(string key, out CacheItemContainer data)
        {
            data = null;
            if (RedisCache.Contains(key))
            {
                data = RedisCache.Get <CacheItemContainer <T> >(key);
                if (data == null || data.IsExpired(TimeToLive))
                {
                    data = null;
                    return(false);
                }

                return(true);
            }

            return(false);
        }
示例#7
0
        public static void ProcessProviderAction(CacheBehavior cacheBehavior, CacheAction cacheAction)
        {
            // Step 1. Get cache key
            string cacheKey = cacheBehavior.GetCacheKey(cacheAction.Item);

            // Step 2. Get cache value
            CacheItemContainer <Provider> providerContainer = CacheHelper2.GetCacheValue <CacheItemContainer <Provider> >(cacheKey);

            if (providerContainer == null)
            {
                return;
            }

            // Step 3. Refresh
            Provider provider = new GetProvider()
            {
                Id = providerContainer.Item.Id
            }.ExecuteItem(false);

            providerContainer.Item = provider;
        }
        public bool TryGetValue(string key, Type type, out CacheItemContainer data)
        {
            data = null;
            if (RedisCache.Contains(key))
            {
                var genericContainerType = genericCacheItemContainer.GetOrAdd(type, t =>
                {
                    return(typeof(CacheItemContainer <>).MakeGenericType(t));
                });

                data = RedisCache.Get(key, genericContainerType) as CacheItemContainer;
                if (data == null || data.IsExpired(TimeToLive))
                {
                    data = null;
                    return(false);
                }

                return(true);
            }

            return(false);
        }
示例#9
0
        public override void Set(string key, object entry, DateTime utcExpiry)
        {
            var cache    = GetCache();
            var cacheKey = GetCacheKey(key);

            var container = new CacheItemContainer(entry);

            if (CacheItemDependenciesEnabled)
            {
                var policy = GetPolicy(cache, utcExpiry, CacheRegionName);

                container.Detail = this.IncludeCacheItemDetails
                                        ? cache.CreateCacheItemDetailObject(cacheKey, policy, CacheRegionName)
                                        : null;

                cache.Set(cacheKey, container, policy, CacheRegionName);

                return;
            }

            cache.Set(cacheKey, container, ToDateTimeOffset(utcExpiry), CacheRegionName);
        }
示例#10
0
        public override object Add(string key, object entry, DateTime utcExpiry)
        {
            var cache    = GetCache();
            var cacheKey = GetCacheKey(key);

            var container = new CacheItemContainer(entry);

            if (CacheItemDependenciesEnabled)
            {
                var policy = GetPolicy(cache, utcExpiry, CacheRegionName);

                container.Detail = this.IncludeCacheItemDetails
                                        ? cache.CreateCacheItemDetailObject(cacheKey, policy, CacheRegionName)
                                        : null;

                var addedItem = cache.AddOrGetExisting(cacheKey, container, policy, CacheRegionName);

                return((addedItem as CacheItemContainer)?.Value);
            }

            return((cache.AddOrGetExisting(cacheKey, container, ToDateTimeOffset(utcExpiry), CacheRegionName) as CacheItemContainer)?.Value);
        }
示例#11
0
        /// <summary>
        /// Prints cache items data to a table.
        /// </summary>
        /// <param name="cacheItems">Cache items to be printed.</param>
        private DataTable GetCacheItemsData(IEnumerable <string> cacheItems)
        {
            DataTable table = new DataTable("CacheItems");

            table.Columns.Add("Key");
            table.Columns.Add("Data");
            table.Columns.Add("Size");
            table.Columns.Add("Expiration");
            table.Columns.Add("Priority");

            if (cacheItems != null)
            {
                // Process dummy keys
                foreach (string key in cacheItems)
                {
                    if (!String.IsNullOrEmpty(key))
                    {
                        // Process the key
                        object             value     = HttpRuntime.Cache[key];
                        CacheItemContainer container = null;

                        // Handle the container
                        if (value is CacheItemContainer)
                        {
                            container = (CacheItemContainer)value;
                            value     = container.Data;
                        }

                        if (value != CacheHelper.DUMMY_KEY)
                        {
                            PrintCacheItemData(table, key, container, value);
                        }
                    }
                }
            }

            return(table);
        }
示例#12
0
        /// <summary>
        /// Renders the particular cache item.
        /// </summary>
        protected void PrintCacheItemData(DataTable table, string key, CacheItemContainer container, object value)
        {
            if (key.Length > 100)
            {
                key = key.Substring(0, 100);
            }

            int size = 0;

            if ((value != null) && (value != DBNull.Value))
            {
                value = HttpUtility.HtmlEncode(DataHelper.GetObjectString(value, 100, out size));
            }

            object expiration = null;
            object priority   = null;

            if (CacheDebug.Settings.Enabled)
            {
                if (container != null)
                {
                    if (container.AbsoluteExpiration != Cache.NoAbsoluteExpiration)
                    {
                        expiration = container.AbsoluteExpiration;
                    }
                    else
                    {
                        expiration = container.SlidingExpiration;
                    }

                    priority = container.Priority;
                }
            }

            table.Rows.Add(key, value, size, expiration, priority);
        }
    /// <summary>
    /// Renders the particular cache item.
    /// </summary>
    protected void RenderItem(StringBuilder sb, string key, CacheItemContainer container, object value, bool dummy, int i)
    {
        // Add the key row
        string cssClass = ((i % 2) == 0) ? "OddRow" : "EvenRow";

        sb.Append("<tr class=\"");
        sb.Append(cssClass);
        sb.Append("\"><td style=\"white-space: nowrap;\">");

        // Get the action
        GetDeleteAction(key, sb);

        sb.Append("</td><td style=\"white-space: nowrap;\"><span title=\"" + key.Replace("&", "&amp;") + "\">");
        string keyTag = TextHelper.LimitLength(key, 100);
        sb.Append(keyTag.Replace("&", "&amp;"));
        sb.Append("</span></td>");

        if (!dummy)
        {
            sb.Append("<td style=\"white-space: nowrap;\">");

            // Render the value
            if (value != null)
            {
                sb.Append("<a href=\"#\" onclick=\"Show('" + Server.UrlEncode(key) + "')\"");
                sb.Append("><img class=\"UniGridActionButton\" src=\"");
                sb.Append(ResolveUrl(GetImageUrl("Design/Controls/UniGrid/Actions/View.png")));
                sb.Append("\" style=\"border: none;\" alt=\"");
                sb.Append(GetString("General.View"));
                sb.Append("\" title=\"");
                sb.Append(GetString("General.View"));
                sb.Append("\" />");
                sb.Append("</a> ");
                if ((value == null) || (value == DBNull.Value))
                {
                    sb.Append("null");
                }
                else
                {
                    sb.Append(HttpUtility.HtmlEncode(DataHelper.GetObjectString(value, 100)));
                }
            }
            else
            {
                sb.Append("null");
            }

            sb.Append("</td>");

            if (CacheHelper.DebugCache)
            {
                // Expiration
                sb.Append("<td style=\"white-space: nowrap;\">");
                if (container != null)
                {
                    if (container.AbsoluteExpiration != Cache.NoAbsoluteExpiration)
                    {
                        sb.Append(container.AbsoluteExpiration);
                    }
                    else
                    {
                        sb.Append(container.SlidingExpiration);
                    }
                }
                sb.Append("</td>");

                // Expiration
                sb.Append("<td style=\"white-space: nowrap;\">");
                if (container != null)
                {
                    sb.Append(container.Priority);
                }
                sb.Append("</td>");
            }
        }

        sb.Append("</tr>");
    }
    /// <summary>
    /// Renders the particular cache item.
    /// </summary>
    protected void RenderItem(StringBuilder sb, string key, CacheItemContainer container, object value, bool dummy, int i)
    {
        // Add the key row
        string cssClass = ((i % 2) == 0) ? "OddRow" : "EvenRow";

        sb.Append("<tr class=\"");
        sb.Append(cssClass);
        sb.Append("\"><td style=\"white-space: nowrap;\">");

        // Get the action
        GetDeleteAction(key, sb);

        sb.Append("</td><td style=\"white-space: nowrap;\"><span title=\"" + key.Replace("&", "&amp;") + "\">");
        string keyTag = TextHelper.LimitLength(key, 100);

        sb.Append(keyTag.Replace("&", "&amp;"));
        sb.Append("</span></td>");

        if (!dummy)
        {
            sb.Append("<td style=\"white-space: nowrap;\">");

            // Render the value
            if (value != null)
            {
                sb.Append("<a href=\"#\" onclick=\"Show('" + Server.UrlEncode(key) + "')\"");
                sb.Append("><img class=\"UniGridActionButton\" src=\"");
                sb.Append(ResolveUrl(GetImageUrl("Design/Controls/UniGrid/Actions/View.png")));
                sb.Append("\" style=\"border: none;\" alt=\"");
                sb.Append(GetString("General.View"));
                sb.Append("\" title=\"");
                sb.Append(GetString("General.View"));
                sb.Append("\" />");
                sb.Append("</a> ");
                if ((value == null) || (value == DBNull.Value))
                {
                    sb.Append("null");
                }
                else
                {
                    sb.Append(HttpUtility.HtmlEncode(DataHelper.GetObjectString(value, 100)));
                }
            }
            else
            {
                sb.Append("null");
            }

            sb.Append("</td>");

            if (CacheHelper.DebugCache)
            {
                // Expiration
                sb.Append("<td style=\"white-space: nowrap;\">");
                if (container != null)
                {
                    if (container.AbsoluteExpiration != Cache.NoAbsoluteExpiration)
                    {
                        sb.Append(container.AbsoluteExpiration);
                    }
                    else
                    {
                        sb.Append(container.SlidingExpiration);
                    }
                }
                sb.Append("</td>");

                // Expiration
                sb.Append("<td style=\"white-space: nowrap;\">");
                if (container != null)
                {
                    sb.Append(container.Priority);
                }
                sb.Append("</td>");
            }
        }

        sb.Append("</tr>");
    }
    public void ReloadData()
    {
        if (ShowDummyItems)
        {
            lblKey.Text     = GetString("Administration-System.CacheInfoDummyKey");
            plcData.Visible = false;
        }
        else
        {
            lblKey.Text        = GetString("Administration-System.CacheInfoKey");
            lblData.Text       = GetString("Administration-System.CacheInfoData");
            lblExpiration.Text = GetString("Administration-System.CacheInfoExpiration");
            lblPriority.Text   = GetString("Administration-System.CacheInfoPriority");

            plcData.Visible      = true;
            plcContainer.Visible = CacheHelper.DebugCache;
        }

        lblAction.Text = GetString("General.Action");

        // Build the table
        StringBuilder sb = new StringBuilder();

        // Prepare the indexes for paging
        int pageSize = pagerItems.CurrentPageSize;

        int startIndex = (pagerItems.CurrentPage - 1) * pageSize + 1;
        int endIndex   = startIndex + pageSize;

        // Process all items
        int  i   = 0;
        bool all = (endIndex <= startIndex);

        string search = txtFilter.Text;

        if (mAllItems != null)
        {
            if (ShowDummyItems)
            {
                // Process dummy keys
                foreach (string key in mAllItems)
                {
                    if (key.IndexOfCSafe(search, true) >= 0)
                    {
                        if (!String.IsNullOrEmpty(key))
                        {
                            // Process the key
                            object             value     = HttpRuntime.Cache[key];
                            CacheItemContainer container = null;

                            // Handle the container
                            if (value is CacheItemContainer)
                            {
                                container = (CacheItemContainer)value;
                                value     = container.Data;
                            }

                            if (value == CacheHelper.DUMMY_KEY)
                            {
                                i++;
                                if (all || (i >= startIndex) && (i < endIndex))
                                {
                                    RenderItem(sb, key, container, value, true, i);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                // Process only normal keys
                foreach (string key in mAllItems)
                {
                    if (key.IndexOfCSafe(search, true) >= 0)
                    {
                        // Process the key
                        object             value     = HttpRuntime.Cache[key];
                        CacheItemContainer container = null;

                        // Handle the container
                        if (value is CacheItemContainer)
                        {
                            container = (CacheItemContainer)value;
                            value     = container.Data;
                        }

                        if (value != CacheHelper.DUMMY_KEY)
                        {
                            i++;
                            if (all || (i >= startIndex) && (i < endIndex))
                            {
                                RenderItem(sb, key, container, value, false, i);
                            }
                        }
                    }
                }
            }
        }

        mTotalItems      = i;
        plcItems.Visible = (i > 0);
        lblInfo.Visible  = (i <= 0);
        if (!RequestHelper.IsPostBack())
        {
            pnlSearch.Visible = (i > 10);
        }

        ltlCacheInfo.Text = sb.ToString();

        // Call page binding event
        if (OnPageBinding != null)
        {
            OnPageBinding(this, null);
        }
    }
    /// <summary>
    /// Reloads the cache item view.
    /// </summary>
    /// <param name="objectDeleted">True if object was recently deleted</param>
    protected void ReloadData(bool objectDeleted = false)
    {
        object obj = null;

        pnlCacheItem.Visible = !objectDeleted;
        CurrentMaster.HeaderActions.Visible = !objectDeleted;

        switch (mSource.ToLowerCSafe())
        {
        case "cache":
        {
            var cacheAccessor = Service.Resolve <ICacheAccessor>();

            // Get the item from cache
            obj = cacheAccessor.Get(mKey);

            // Take the object from the cache
            if ((obj != null) && !objectDeleted)
            {
                if (obj is CacheItemContainer)
                {
                    // Setup the advanced information
                    CacheItemContainer container = (CacheItemContainer)obj;
                    obj = container.Data;

                    // Get the inner value
                    obj = CacheHelper.GetInnerValue(obj);

                    ltlKey.Text      = HTMLHelper.HTMLEncode(mKey);
                    ltlPriority.Text = container.Priority.ToString();
                    if (container.AbsoluteExpiration != Cache.NoAbsoluteExpiration)
                    {
                        ltlExpiration.Text = container.AbsoluteExpiration.ToString();
                    }
                    else
                    {
                        ltlExpiration.Text = container.SlidingExpiration.ToString();
                    }

                    if (container.Dependencies != null)
                    {
                        gridDependencies.AllItems = container.Dependencies.CacheKeys;
                        gridDependencies.ReloadData();
                    }

                    gridDependencies.Visible = gridDependencies.TotalItems > 0;
                    ltlDependencies.Visible  = gridDependencies.TotalItems == 0;

                    pnlCacheItem.Visible = true;
                }

                pnlBody.Visible = true;
            }
            else if (objectDeleted)
            {
                ShowConfirmation(GetString("general.wasdeleted"), true);
            }
            else
            {
                ShowError(GetString("general.objectnotfound"));
            }
        }
        break;
        }

        objElem.Object = obj;
    }
    /// <summary>
    /// Renders the particular cache item.
    /// </summary>
    protected void RenderItem(StringBuilder sb, string key, CacheItemContainer container, object value, bool dummy)
    {
        sb.Append("<tr><td class=\"unigrid-actions\">");

        // Get the action
        sb.Append(GetViewAction(key));
        sb.Append(GetDeleteAction(key));
        sb.Append(GetDebugAction(key));

        sb.Append("</td><td><span title=\"" + HTMLHelper.HTMLEncode(key) + "\">");
        string keyTag = TextHelper.LimitLength(key, 100);
        sb.Append(HTMLHelper.HTMLEncode(keyTag));
        sb.Append("</span></td>");

        if (!dummy)
        {
            sb.Append("<td>");

            // Render the value
            if ((value != null) && (value != DBNull.Value))
            {
                sb.Append(HttpUtility.HtmlEncode(DataHelper.GetObjectString(value, 100)));
            }
            else
            {
                sb.Append("null");
            }

            sb.Append("</td>");

            if (CacheDebug.Settings.Enabled)
            {
                // Expiration
                sb.Append("<td>");
                if (container != null)
                {
                    if (container.AbsoluteExpiration != Cache.NoAbsoluteExpiration)
                    {
                        sb.Append(container.AbsoluteExpiration);
                    }
                    else
                    {
                        sb.Append(container.SlidingExpiration);
                    }
                }
                sb.Append("</td>");

                // Expiration
                sb.Append("<td>");
                if (container != null)
                {
                    sb.Append(container.Priority);
                }
                sb.Append("</td>");
            }
        }

        sb.Append("</tr>");
    }
示例#18
0
    public void ReloadData()
    {
        if (ShowDummyItems)
        {
            lblKey.Text     = GetString("Administration-System.CacheInfoDummyKey");
            plcData.Visible = false;
        }
        else
        {
            lblKey.Text        = GetString("Administration-System.CacheInfoKey");
            lblData.Text       = GetString("Administration-System.CacheInfoData");
            lblExpiration.Text = GetString("Administration-System.CacheInfoExpiration");
            lblPriority.Text   = GetString("Administration-System.CacheInfoPriority");

            plcData.Visible      = true;
            plcContainer.Visible = CacheDebug.Settings.Enabled;
        }

        lblAction.Text = GetString("General.Action");

        // Build the table
        StringBuilder sb = new StringBuilder();

        // Prepare the indexes for paging
        int pageSize = pagerItems.CurrentPageSize;

        int startIndex = (pagerItems.CurrentPage - 1) * pageSize + 1;
        int endIndex   = startIndex + pageSize;

        // Process all items
        int  filteredCount = 0;
        int  count         = 0;
        bool all           = (endIndex <= startIndex);

        var cacheAccessor = Service.Resolve <ICacheAccessor>();

        string search = txtFilter.Text;

        if (AllItems != null)
        {
            // Process dummy keys
            foreach (string key in AllItems)
            {
                count++;

                if (key.IndexOfCSafe(search, true) >= 0)
                {
                    if (!String.IsNullOrEmpty(key) || !ShowDummyItems)
                    {
                        // Process the key
                        object             value     = cacheAccessor.Get(key);
                        CacheItemContainer container = null;

                        // Handle the container
                        if (value is CacheItemContainer)
                        {
                            container = (CacheItemContainer)value;
                            value     = container.Data;
                        }

                        if ((ShowDummyItems && value == CacheHelper.DUMMY_KEY) || (!ShowDummyItems && value != CacheHelper.DUMMY_KEY))
                        {
                            filteredCount++;

                            if (all || (filteredCount >= startIndex) && (filteredCount < endIndex))
                            {
                                RenderItem(sb, key, container, value, ShowDummyItems);
                            }
                        }
                    }
                }
            }

            TotalItems         = count;
            TotalFilteredItems = filteredCount;

            lblInfo.Visible   = (filteredCount <= 0);
            plcItems.Visible  = (filteredCount > 0);
            pnlSearch.Visible = (count > 2);

            ltlCacheInfo.Text = sb.ToString();

            // Call page binding event
            if (OnPageBinding != null)
            {
                OnPageBinding(this, null);
            }
        }
    }
    protected void ReloadData()
    {
        object obj = null;

        switch (source.ToLowerCSafe())
        {
        case "cache":
        {
            // Get the item from cache
            obj = HttpRuntime.Cache[key];

            // Take the object from the cache
            if (obj != null)
            {
                pnlActions.Visible = true;

                if (obj is CacheItemContainer)
                {
                    // Setup the advanced information
                    CacheItemContainer container = (CacheItemContainer)obj;
                    obj = container.Data;

                    // Get the inner value
                    obj = CacheHelper.GetInnerValue(obj);

                    ltlKey.Text      = key;
                    ltlPriority.Text = container.Priority.ToString();
                    if (container.AbsoluteExpiration != Cache.NoAbsoluteExpiration)
                    {
                        ltlExpiration.Text = container.AbsoluteExpiration.ToString();
                    }
                    else
                    {
                        ltlExpiration.Text = container.SlidingExpiration.ToString();
                    }

                    // Additional info
                    if (container.Dependencies is CMSCacheDependency)
                    {
                        CMSCacheDependency cd = (CMSCacheDependency)container.Dependencies;

                        if (!RequestHelper.IsPostBack())
                        {
                            gridDependencies.PagerControl.UniPager.PageSize = 10;
                        }

                        gridDependencies.AllItems = cd.CacheKeys;
                        gridDependencies.ReloadData();
                    }

                    gridDependencies.Visible = gridDependencies.TotalItems > 0;
                    ltlDependencies.Visible  = gridDependencies.TotalItems == 0;

                    pnlCacheItem.Visible = true;
                }
            }
            else if (wasDeleted)
            {
                ShowError(GetString("general.wasdeleted"));
            }
            else
            {
                ShowError(GetString("general.objectnotfound"));
            }
        }
        break;
        }

        objElem.Object = obj;
    }