1
- using System . Web . Mvc ;
1
+ using System ;
2
+ using System . Web . Mvc ;
3
+ using Newtonsoft . Json ;
2
4
using Our . Umbraco . DocTypeGridEditor . Web . Attributes ;
3
5
using Our . Umbraco . DocTypeGridEditor . Web . Mvc ;
4
6
using Umbraco . Core ;
5
- using Umbraco . Core . Events ;
6
- using Umbraco . Core . Models ;
7
- using Umbraco . Core . Services ;
7
+ using Umbraco . Core . Sync ;
8
+ using Umbraco . Web . Cache ;
8
9
9
10
namespace Our . Umbraco . DocTypeGridEditor
10
11
{
@@ -22,32 +23,45 @@ protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplic
22
23
23
24
protected override void ApplicationStarted ( UmbracoApplicationBase umbracoApplication , ApplicationContext applicationContext )
24
25
{
25
- DataTypeService . Saved += ExpireDataTypeCache ;
26
- ContentTypeService . SavedContentType += ExpireContentTypeCache ;
27
- }
28
-
29
- private void ExpireDataTypeCache ( IDataTypeService sender , SaveEventArgs < IDataTypeDefinition > e )
30
- {
31
- foreach ( var dataType in e . SavedEntities )
26
+ DataTypeCacheRefresher . CacheUpdated += ( sender , e ) =>
32
27
{
33
- ApplicationContext . Current . ApplicationCache . RuntimeCache . ClearCacheItem (
34
- string . Concat ( "Our.Umbraco.DocTypeGridEditor.Web.Extensions.ContentTypeServiceExtensions.GetAliasById_" , dataType . Key ) ) ;
28
+ if ( e . MessageType == MessageType . RefreshByJson )
29
+ {
30
+ var payload = JsonConvert . DeserializeAnonymousType ( ( string ) e . MessageObject , new [ ] { new { Id = default ( int ) , UniqueId = default ( Guid ) } } ) ;
31
+ if ( payload != null )
32
+ {
33
+ foreach ( var item in payload )
34
+ {
35
+ applicationContext . ApplicationCache . RuntimeCache . ClearCacheItem (
36
+ string . Concat ( "Our.Umbraco.DocTypeGridEditor.Web.Extensions.ContentTypeServiceExtensions.GetAliasById_" , item . UniqueId ) ) ;
35
37
36
- ApplicationContext . Current . ApplicationCache . RuntimeCache . ClearCacheItem (
37
- string . Concat ( "Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetPreValuesCollectionByDataTypeId_" , dataType . Id ) ) ;
38
- }
39
- }
38
+ applicationContext . ApplicationCache . RuntimeCache . ClearCacheItem (
39
+ string . Concat ( "Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetPreValuesCollectionByDataTypeId_" , item . Id ) ) ;
40
+ }
41
+ }
42
+ }
43
+ } ;
40
44
41
- private void ExpireContentTypeCache ( IContentTypeService sender , SaveEventArgs < IContentType > e )
42
- {
43
- foreach ( var contentType in e . SavedEntities )
45
+ ContentTypeCacheRefresher . CacheUpdated += ( sender , e ) =>
44
46
{
45
- ApplicationContext . Current . ApplicationCache . RuntimeCache . ClearCacheItem (
46
- string . Concat ( "Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetContentTypesByAlias_" , contentType . Alias ) ) ;
47
+ if ( e . MessageType == MessageType . RefreshByJson )
48
+ {
49
+ var payload = JsonConvert . DeserializeAnonymousType ( ( string ) e . MessageObject , new [ ] { new { Alias = default ( string ) } } ) ;
50
+ if ( payload != null )
51
+ {
52
+ foreach ( var item in payload )
53
+ {
54
+ applicationContext . ApplicationCache . RuntimeCache . ClearCacheItem (
55
+ string . Concat ( "Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetContentTypesByAlias_" , item . Alias ) ) ;
47
56
48
- ApplicationContext . Current . ApplicationCache . RuntimeCache . ClearCacheItem (
49
- string . Concat ( "Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetContentTypeAliasByGuid_" , contentType . Key ) ) ;
50
- }
57
+ // NOTE: Unsure how to get the doctype GUID, without hitting the database?
58
+ // So we end up clearing the entire cache for this key. [LK:2018-01-30]
59
+ applicationContext . ApplicationCache . RuntimeCache . ClearCacheByKeySearch (
60
+ "Our.Umbraco.DocTypeGridEditor.Helpers.DocTypeGridEditorHelper.GetContentTypeAliasByGuid_" ) ;
61
+ }
62
+ }
63
+ }
64
+ } ;
51
65
}
52
66
}
53
67
}
0 commit comments