private PreValueCollection GetCachedPreValueCollection(int datetypeId) { var key = GetPrefixedCacheKey(datetypeId); return(IsolatedCache.GetCacheItem <PreValueCollection>(key, () => { var dtos = Database.Fetch <DataTypePreValueDto>("WHERE datatypeNodeId = @Id", new { Id = datetypeId }); var list = dtos.Select(x => new Tuple <PreValue, string, int>(new PreValue(x.Id, x.Value, x.SortOrder), x.Alias, x.SortOrder)).ToList(); var collection = PreValueConverter.ConvertToPreValuesCollection(list); return collection; }, TimeSpan.FromMinutes(20), isSliding: true)); }
private PreValueCollection GetAndCachePreValueCollection(int dataTypeId) { //go get the data var dtos = Database.Fetch <DataTypePreValueDto>("WHERE datatypeNodeId = @Id", new { Id = dataTypeId }); var list = dtos.Select(x => new Tuple <PreValue, string, int>(new PreValue(x.Id, x.Value, x.SortOrder), x.Alias, x.SortOrder)).ToList(); var collection = PreValueConverter.ConvertToPreValuesCollection(list); //now create the cache key, this needs to include all pre-value ids so that we can use this cached item in the GetPreValuesAsString method //the key will be: "UmbracoPreValDATATYPEID-CSVOFPREVALIDS var key = GetPrefixedCacheKey(dataTypeId) + string.Join(",", collection.FormatAsDictionary().Select(x => x.Value.Id).ToArray()); //store into cache _cacheHelper.RuntimeCache.InsertCacheItem(key, () => collection, //30 mins new TimeSpan(0, 0, 30), //sliding is true true); return(collection); }