Clearing system Cache from a web page (C#) in Kentico

Woodley Westbrook asked on September 6, 2018 21:50

Hello Kentico DevNet,

We have our website up and running using Kentico.

We would like to give non Administrative personnel the ability to "Clear System Cache" by clicking a button on a C# web page (located within the same Kentico environment). We do not want them to have access to the "System" portion of the application so that we may limit the harm they could possibly do to the website.

The page would be very simple in design. Just a button that they would click to clear system cache and maybe a label that would confirm their submission.

Have looked for examples but so far have found nothing.

Any suggestions or examples would be appreciated.

We are using Kentico 10.

Thanks

Woodley Westbrook

Correct Answer

Michal Samuhel answered on September 6, 2018 21:56

Hi Woodley,

For UI actions, you can always take a look at particular module and its controls. \CMS\CMSModules\System\Controls\System.ascx.cs is class you are looking for. Button action is called with a method that clears Cache on application first and even calls GC for cleanup:

 protected void ClearCache(object sender = null, EventArgs args = null)
    {
        if (StopProcessing)
        {
            return;
        }

        // Clear the cache
        CacheHelper.ClearCache(null, true);
        Functions.ClearHashtables();

        // Drop the routes
        CMSDocumentRouteHelper.DropAllRoutes();

        // Disposes all zip files
        ZipStorageProvider.DisposeAll();

        // Collect the memory
        GC.Collect();
        GC.WaitForPendingFinalizers();

        // Log event
        EventLogProvider.LogEvent(EventType.INFORMATION, "System", "CLEARCACHE", GetString("Administration-System.ClearCacheSuccess"));

        ShowConfirmation(GetString("Administration-System.ClearCacheSuccess"));

        LoadData();
    }
2 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.