Exemplo n.º 1
0
        /// <summary>
        /// Flushes the cache.
        /// </summary>
        /// <param name="id">The id.</param>
        public static void FlushFromCache(int id)
        {
            //Ensure that MediaTypes are reloaded from db by clearing cache
            InMemoryCacheProvider.Current.Clear();

            var ct = new ContentType(id);
            ApplicationContext.Current.ApplicationCache.ClearCacheItem(string.Format("{0}{1}", CacheKeys.ContentTypeCacheKey, id));
            ApplicationContext.Current.ApplicationCache.ClearCacheItem(ct.GetPropertiesCacheKey());
            ct.ClearVirtualTabs();

            //clear the content type from the property datatype cache used by razor
            RemoveFromDataTypeCache(ct.Alias);

            // clear anything that uses this as master content type
            //TODO: Update to load all content types
            //Should this include "ct.nodeObjectType == media.MediaType._objectType" ?
            if (ct.nodeObjectType == DocumentType._objectType)
            {
                //NOTE Changed from "DocumentType.GetAllAsList().FindAll(dt => dt.MasterContentType == id)" to loading master contenttypes directly from the db.
                //Related to http://issues.umbraco.org/issue/U4-1714
                var dtos = ApplicationContext.Current.DatabaseContext.Database.Fetch<ContentType2ContentTypeDto>("WHERE parentContentTypeId = @Id", new { Id = id });
                foreach (var dto in dtos)
                {
                    FlushFromCache(dto.ChildId);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Flushes the cache.
        /// </summary>
        /// <param name="Id">The id.</param>
        public static void FlushFromCache(int id)
        {
            ContentType ct = new ContentType(id);
            Cache.ClearCacheItem(string.Format("UmbracoContentType{0}", id));
            Cache.ClearCacheItem(ct.GetPropertiesCacheKey());
            ct.ClearVirtualTabs();

            //clear the content type from the property datatype cache used by razor
            RemoveFromDataTypeCache(ct.Alias);

            // clear anything that uses this as master content type
            if (ct.nodeObjectType == DocumentType._objectType)
            {
                List<DocumentType> cacheToFlush = DocumentType.GetAllAsList().FindAll(dt => dt.MasterContentType == id);
                foreach (DocumentType dt in cacheToFlush)
                    FlushFromCache(dt.Id);

            }
        }