UWP: Publisher Cache

One other way to make communications between applications of the same publisher is publisher cache folder. The idea is to create a special folder or folders, which are assigned not to applications but to the publisher. So, if the publisher creates a bunch of applications and wants to share some data between them, it’s possible to use cache folders.

In order to create a publisher cache folder(s) developers should use the manifest file like this:

 <Extensions>
 <Extension Category ="windows.publisherCacheFolders">
 <PublisherCacheFolders>
 <Folder Name="myFolder"/>
 </PublisherCacheFolders>
 </Extension>
</Extensions>

In this case I have created just one folder and “created” is the right word there because the folder will be created automatically based on the manifest of the application. Pay special attention that this folder will be created in a special directory which is associated with the publisher rather than with the application. In my case, the folder looks like C:\Users\Sergey\AppData\Local\Publishers\kj4a6z6kv5v3p\myFolder.

Of course, in order to start working with this folder (these folders) you just need to get a reference to StorageFolder object and you can make it using ApplicationData class:

 var f = ApplicationData.Current.GetPublisherCacheFolder("myFolder");

Right after you get access to the folder, you can create subfolders, check files inside and make any of available operations there as with a simple StorageFolder object.

If you want to clear the publisher cache folder you can do it using ClearPublisherCacheFolderAsync method:

 ApplicationData.Current.ClearPublisherCacheFolderAsync("myFolder");

That’s all. You can see that it’s easy and it’s a good opportunity to share data between applications for enterprise if developers need to implement a bunch of different applications but with common settings, temp files etc.