diff --git a/src/Umbraco.Core/Persistence/PetaPoco.cs b/src/Umbraco.Core/Persistence/PetaPoco.cs index 9ca0c11d19..21f97643ec 100644 --- a/src/Umbraco.Core/Persistence/PetaPoco.cs +++ b/src/Umbraco.Core/Persistence/PetaPoco.cs @@ -1704,13 +1704,16 @@ namespace Umbraco.Core.Persistence } static readonly ObjectCache ObjectCache = new MemoryCache("NPoco"); + } public class PocoData { //USE ONLY FOR TESTING internal static bool UseLongKeys = false; - + //USE ONLY FOR TESTING - default is one hr + internal static int SlidingExpirationSeconds = 3600; + public static PocoData ForObject(object o, string primaryKeyName) { var t = o.GetType(); @@ -2078,7 +2081,7 @@ namespace Umbraco.Core.Persistence { //sliding expiration of 1 hr, if the same key isn't used in this // timeframe it will be removed from the cache - SlidingExpiration = new TimeSpan(1,0,0) + SlidingExpiration = new TimeSpan(0, 0, SlidingExpirationSeconds) }); return (value ?? newValue).Value; // Lazy handles the locking itself @@ -2170,7 +2173,7 @@ namespace Umbraco.Core.Persistence public TableInfo TableInfo { get; private set; } public Dictionary Columns { get; private set; } static System.Threading.ReaderWriterLockSlim InnerLock = new System.Threading.ReaderWriterLockSlim(); - + /// /// Returns a report of the current cache being utilized by PetaPoco /// diff --git a/src/Umbraco.Core/Persistence/Repositories/TagRepository.cs b/src/Umbraco.Core/Persistence/Repositories/TagRepository.cs index 2fa7335987..bb7ecc3c0a 100644 --- a/src/Umbraco.Core/Persistence/Repositories/TagRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/TagRepository.cs @@ -163,6 +163,8 @@ namespace Umbraco.Core.Persistence.Repositories //TODO: Consider caching implications. + //TODO: We need to add lookups for parentId or path! (i.e. get content in tag group that are descendants of x) + public IEnumerable GetTaggedEntitiesByTagGroup(TaggableObjectTypes objectType, string tagGroup) { diff --git a/src/Umbraco.Tests/Persistence/PetaPocoExtensionsTest.cs b/src/Umbraco.Tests/Persistence/PetaPocoExtensionsTest.cs index 0192517990..9d17fc17f6 100644 --- a/src/Umbraco.Tests/Persistence/PetaPocoExtensionsTest.cs +++ b/src/Umbraco.Tests/Persistence/PetaPocoExtensionsTest.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; +using System.Threading; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Models; @@ -73,6 +74,29 @@ namespace Umbraco.Tests.Persistence Assert.AreEqual(1, totalKeys.Count()); } + [Test] + public void Verify_Memory_Expires() + { + Database.PocoData.SlidingExpirationSeconds = 2; + + var managedCache = new Database.ManagedCache(); + + int id1, id2, id3; + string alias; + CreateStuff(out id1, out id2, out id3, out alias); + QueryStuff(id1, id2, id3, alias); + + var count1 = managedCache.GetCache().GetCount(); + Console.WriteLine("Keys = " + count1); + Assert.Greater(count1, 0); + + Thread.Sleep(10000); + + var count2 = managedCache.GetCache().GetCount(); + Console.WriteLine("Keys = " + count2); + Assert.Less(count2, count1); + } + private void QueryStuff(int id1, int id2, int id3, string alias1) { var contentService = ServiceContext.ContentService;