Пример #1
0
        /// <summary>
        /// Removes the page item from the cache if it exists.
        /// </summary>
        /// <param name="id">The id of the page.</param>
        /// <param name="version">The page content version.</param>
        public void Remove(int id, int version)
        {
            if (!_applicationSettings.UseObjectCache)
            {
                return;
            }

            string key = CacheKeys.PageViewModelKey(id, version);

            _cache.Remove(key);

            Log("Removed key '{0}' from cache", key);
        }
Пример #2
0
        /// <summary>
        /// Retrieves the page item for a specific version of the page from the cache, or null if it doesn't exist.
        /// </summary>
        /// <param name="id">The id of the page </param>
        /// <param name="version">The version of the page.</param>
        /// <returns>The cached <see cref="PageViewModel"/>; or null if it doesn't exist.</returns>
        public PageViewModel Get(int id, int version)
        {
            if (!_applicationSettings.UseObjectCache)
            {
                return(null);
            }

            string key = CacheKeys.PageViewModelKey(id, version);

            Log("Get key {0} in cache [Id={1}, Version{2}]", key, id, version);

            return(_cache.Get(key) as PageViewModel);
        }
Пример #3
0
        // <summary>
        /// Adds an item to the cache.
        /// </summary>
        /// <param name="id">The page's Id.</param>
        /// <param name="version">The pages content's version.</param>
        /// <param name="item">The page.</param>
        public void Add(int id, int version, PageViewModel item)
        {
            if (!_applicationSettings.UseObjectCache)
            {
                return;
            }

            if (!item.IsCacheable)
            {
                return;
            }

            string key = CacheKeys.PageViewModelKey(id, version);

            _cache.Add(key, item, new CacheItemPolicy());

            Log("Added key {0} to cache [Id={1}, Version{2}]", key, id, version);
        }