Skip to content

Commit 2dc7ed1

Browse files
committed
Added caching option
Updated cache key Refactored
1 parent db56937 commit 2dc7ed1

13 files changed

+121
-83
lines changed

Perplex.Umbraco.Forms/App_Plugins/PerplexUmbracoForms/PerplexUmbracoForms.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,8 @@
4444
<PerplexRecaptchConfig>
4545
<ErrorMessage />
4646
</PerplexRecaptchConfig>
47+
<PerplexCacheConfig>
48+
<EnableCache>true</EnableCache>
49+
<CacheDurationInMinutes>10</CacheDurationInMinutes>
50+
</PerplexCacheConfig>
4751
</PerplexUmbracoFormsConfig>

Perplex.Umbraco.Forms/Code/Configuration/ExtensionConfig.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using System.Xml.Serialization;
1+
using System.Xml.Serialization;
72

83
namespace PerplexUmbraco.Forms.Code.Configuration
94
{

Perplex.Umbraco.Forms/Code/Configuration/FieldTypeConfig.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
62
using System.Xml.Serialization;
73

84
namespace PerplexUmbraco.Forms.Code.Configuration

Perplex.Umbraco.Forms/Code/Configuration/PerplexBaseFileConfig.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
1+
using System.Collections.Generic;
62
using System.Xml.Serialization;
73

84
namespace PerplexUmbraco.Forms.Code.Configuration
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Xml.Serialization;
2+
3+
namespace PerplexUmbraco.Forms.Code.Configuration
4+
{
5+
[XmlType("PerplexCacheConfig")]
6+
public class PerplexCacheConfig
7+
{
8+
[XmlElement("CacheDurationInMinutes")]
9+
public int CacheDurationInMinutes { get; set; }
10+
11+
[XmlElement("EnableCache")]
12+
public bool EnableCache { get; set; }
13+
}
14+
}

Perplex.Umbraco.Forms/Code/Configuration/PerplexFileUploadConfig.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using System.Xml.Serialization;
1+
using System.Xml.Serialization;
72

83
namespace PerplexUmbraco.Forms.Code.Configuration
94
{

Perplex.Umbraco.Forms/Code/Configuration/PerplexImageUploadConfig.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using System.Xml.Serialization;
1+
using System.Xml.Serialization;
72

83
namespace PerplexUmbraco.Forms.Code.Configuration
94
{

Perplex.Umbraco.Forms/Code/Configuration/PerplexRecaptchaConfig.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using System.Xml.Serialization;
1+
using System.Xml.Serialization;
72

83
namespace PerplexUmbraco.Forms.Code.Configuration
94
{

Perplex.Umbraco.Forms/Code/Configuration/PerplexUmbracoFormsConfig.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
74
using System.Web.Hosting;
85
using System.Xml.Serialization;
6+
97
using static PerplexUmbraco.Forms.Code.Constants;
108

119
namespace PerplexUmbraco.Forms.Code.Configuration
@@ -73,6 +71,8 @@ public static void CreateIfNotExists()
7371

7472
public PerplexRecaptchaConfig PerplexRecaptchaConfig { get; set; }
7573

74+
public PerplexCacheConfig PerplexCacheConfig { get; set; }
75+
7676
private static string GetFilePath()
7777
{
7878
return HostingEnvironment.MapPath(Constants.CONFIGURATION_FILE_PATH);
@@ -139,6 +139,12 @@ private static string GetFilePath()
139139
PerplexRecaptchaConfig = new PerplexRecaptchaConfig
140140
{
141141
ErrorMessage = ""
142+
},
143+
144+
PerplexCacheConfig = new PerplexCacheConfig
145+
{
146+
EnableCache = false,
147+
CacheDurationInMinutes = 10
142148
}
143149
};
144150
}

Perplex.Umbraco.Forms/Code/UmbracoEvents.cs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
using System.Linq;
1+
using System;
2+
using System.Linq;
23
using System.Web;
4+
5+
using PerplexUmbraco.Forms.Code.Configuration;
6+
37
using Umbraco.Core;
48
using Umbraco.Core.Logging;
5-
using PerplexUmbraco.Forms.Code.Configuration;
6-
using Umbraco.Web;
7-
using Umbraco.Forms.Data.Storage;
8-
using System;
99
using Umbraco.Forms.Core;
10+
using Umbraco.Forms.Data.Storage;
11+
using Umbraco.Web;
1012

1113
namespace PerplexUmbraco.Forms.Code
1214
{
@@ -64,6 +66,8 @@ void FormStorage_Created(object sender, FormEventArgs e)
6466

6567
folder.Forms.Add(form.Id.ToString());
6668
PerplexFolder.SaveAll();
69+
70+
ClearFormsCache(folderId.ToString());
6771
}
6872

6973
void FormStorage_Deleted(object sender, FormEventArgs e)
@@ -75,7 +79,23 @@ void FormStorage_Deleted(object sender, FormEventArgs e)
7579
{
7680
folder.Forms.Remove(form.Id.ToString());
7781
PerplexFolder.SaveAll();
82+
83+
ClearFormsCache(folder.Id);
84+
}
85+
}
86+
87+
void ClearFormsCache(string folderId)
88+
{
89+
var cacheConfig = PerplexUmbracoFormsConfig.Get.PerplexCacheConfig;
90+
91+
if (cacheConfig.EnableCache)
92+
{
93+
var cacheKey = $"PerplexFormTreeController_GetTreeNodes_id:{folderId}";
94+
var rtCache = ApplicationContext.Current.ApplicationCache.RuntimeCache;
95+
96+
if (rtCache.GetCacheItemsByKeySearch(cacheKey).Any())
97+
rtCache.ClearCacheByKeySearch(cacheKey);
7898
}
7999
}
80100
}
81-
}
101+
}

0 commit comments

Comments
 (0)