API Questions on Kentico API.
Version 5.x > API > clearing cache via api from outside of the cms project View modes: 
User avatar
Member
Member
andrejg - 12/2/2011 1:42:48 PM
   
clearing cache via api from outside of the cms project
Hi,

is there a way to clear the cache of a Kentico website via the API from a project different from the CMS one?

I've followed this guide and I can call the APIs, but they appear to do nothing.

I've tried clearing the cache via CMS.GlobalHelper.CacheHelper.ClearCache (or ClearFullPageCache and ClearPartialCache) and via the following method (found somewhere on the forums):

IDictionaryEnumerator CacheEnum = Cache.GetEnumerator();
while (CacheEnum.MoveNext())
{
string key = CacheEnum.Key.ToString();
Cache.Remove(key);
}

The code executes ok, but it doesn't do anything.

If I create a WebPart (e.g. a button that executes the above code) and place it on the actual website it works ok.
We use Kentico v5.5.3926 on both servers.


Let me describe my situation:
We have two websites, one internal that is used for previewing the content to be published (and to lessen the load on the server when publishing from our editorial system, but that's another story altogether :)) and one external which is visible to the users.

Our editors publish content on the internal website, check it out and when they are satisfied they replicate it to the external server.

We use SQL replication and RoboCopy (for the attachments which are stored in the filesystem) because it's so much faster than Kentico's content staging (replicating some 40 articles takes ~1 minute via SQL and ~30-45 minutes via Kentico's content staging).

The new content eventually appears on the external website (when the old content expires from the cache, more or less), the problem is with page templates; they are in the database, however Kentico doesn't load them unless the cache is cleared.

I have a website that our editors use to start the SQL replication; I had the idea that I could use the API to clear the cache after the replication is complete.

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 12/22/2011 7:53:08 AM
   
RE:clearing cache via api from outside of the cms project
Hi,

The idea with clearing the cache is fine.
However, the situation is that the only way to clear a remote application cache would be to create and run a web service on that application and call that web service remotely from the source application instance.

Since Kentico CMS is a standard ASP.NET application, you can create and use the web service in the same way you would use it in other standard .NET application.

Hope this makes sense.

Regards,
Zdenek