Posts

Showing posts from July, 2016

Getting Umbraco Content - IPublishedContent vs IContent vs Node vs Document

There are couple of ways to get Umbraco content. Some returns the data from db and some does from the cache. Here is some details about them and how you use it in an umbraco project.

IContent is managed by IContentService and is targetted at back-end, read-write access to content. It's what you want to use when you need to manage content.IPublishedContent is managed by the "content cache" and is targetted at front-end, read-only access to content. It's what you want to user when rendering content.Document and INode are (roughly) the legacy equivalents of IContent and IPublishedContent. They should not be used anymore, and will eventually be obsoleted entirely. So better ignore them.
Way 1 var contentService = new ContentService(); IContent content = contentService.GetById(123); Gets the content from the database.Returns both published and unpublished content.Preferred way to get editable content for CRUD operations in Umbraco 7+.Way 2 var umbracoHelper = new UmbracoHelpe…

Cache Handler

Below is a CacheHandler that might be useful to store data in cache objects so rather than returning the data from db, we can return it from the Cache objects

// CacheHanlder.cs
using XYZProject.Infrastructure.Constants; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web; using System.Web.Caching; using System.Web.Configuration;
namespace XYZProject.Infrastructure.EventHandlers { publicstaticclassCacheHandler     { ///<summary> /// Returns ExpirationMinutes from Web.config ///</summary> privatestaticint ExpirationMinutes         { get             { return ToInt32(WebConfigurationManager.AppSettings["CacheExpirationMinutes"]);             }