-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathCacheInvalidationComponent.cs
More file actions
69 lines (56 loc) · 2.21 KB
/
CacheInvalidationComponent.cs
File metadata and controls
69 lines (56 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.ComponentModel;
using System.Linq;
using nuPickers.Caching;
using Umbraco.Core.Events;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
namespace nuPickers.Components
{
public class CacheInvalidationComponent : IComponent, Umbraco.Core.Composing.IComponent
{
private ContentService _contentService;
private DataTypeService _dataTypeService;
public CacheInvalidationComponent(ContentService contentService, DataTypeService dataTypeService)
{
_contentService = contentService;
_dataTypeService = dataTypeService;
}
public void Dispose()
{
}
public ISite Site { get; set; }
public event EventHandler Disposed;
public void Initialize()
{
ContentService.Saved += this.ContentService_Saved;
ContentService.Deleted += this.ContentService_Deleted;
DataTypeService.Saved += this.DataTypeService_Saved;
DataTypeService.Deleted += this.DataTypeService_Deleted;
}
public void Terminate()
{
}
private void ContentService_Saved(IContentService sender, SaveEventArgs<IContent> e)
{
e.SavedEntities.ToList().ForEach(x =>
Cache.Instance.Remove(y => y.StartsWith(CacheConstants.PickedKeysPrefix + x.Id.ToString())));
}
private void ContentService_Deleted(IContentService sender, DeleteEventArgs<IContent> e)
{
e.DeletedEntities.ToList().ForEach(x =>
Cache.Instance.Remove(y => y.StartsWith(CacheConstants.PickedKeysPrefix + x.Id.ToString())));
}
private void DataTypeService_Saved(IDataTypeService sender, SaveEventArgs<IDataType> e)
{
e.SavedEntities.ToList().ForEach(
x => Cache.Instance.Remove(CacheConstants.DataTypePreValuesPrefix + x.Id.ToString()));
}
private void DataTypeService_Deleted(IDataTypeService sender, DeleteEventArgs<IDataType> e)
{
e.DeletedEntities.ToList().ForEach(x =>
Cache.Instance.Remove(CacheConstants.DataTypePreValuesPrefix + x.Id.ToString()));
}
}
}