Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Shaishav Karnani from digitallymedia.com 354 posts 1638 karma points
    Jan 15, 2024 @ 16:22
    Shaishav Karnani from digitallymedia.com
    0

    How to add Output Caching in Umbraco 13?

    I have added a composer for Output Caching. This has been working on .net 7 but not on .net 8

    Please can you suggest how we can get it working.

    public class OutputCacheComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            builder.Services.AddOutputCache(options =>
            {
                options.AddPolicy("Onehour", b =>
                {
                    b.Expire(TimeSpan.FromHours(1));
                    b.Cache();
                });
            });
    
            builder.Services.Configure<UmbracoPipelineOptions>(options =>
            {
                options.AddFilter(new UmbracoPipelineFilter("OutputCache")
                {
                    PostPipeline = app => app.UseOutputCache() 
                });
            });
        }
    }
    
    
    public class DefaultController : AsyncRenderController
    {
    
        private readonly IModelLogic _modelLogic;
    
        public DefaultController(ILogger<DefaultController> logger,
            ICompositeViewEngine compositeViewEngine,
            IUmbracoContextAccessor umbracoContextAccessor,
            IModelLogic modelLogic)
        : base(logger, compositeViewEngine, umbracoContextAccessor)
        {
            _modelLogic = modelLogic;
        }
    
        [OutputCache(PolicyName = "OutputCache")]
        public async new Task<IActionResult> Index()
        {
            var masterModel = await _modelLogic.CreateMasterModel(CurrentPage);
            return this.CurrentTemplate(masterModel);
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft