Cached​File​Updater Cached​File​Updater Cached​File​Updater Cached​File​Updater Class

Definition

Manages files so that they can be updated in real-time by an app that participates in the Cached File Updater contract.

public : static class CachedFileUpdaterpublic static class CachedFileUpdaterPublic Static Class CachedFileUpdater// You can use this class in JavaScript.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0 - for Xbox, see UWP features that aren't yet supported on Xbox)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

The File picker contracts sample demonstrates how to set update information for a file in its TargetFileRequested event handler.


private async void OnTargetFileRequested(FileSavePickerUI sender, TargetFileRequestedEventArgs e)
{
    // Handle the TargetFileRequested event on the background thread on which it was raised

    // Requesting a deferral allows the app to call another asynchronous method and complete the request at a later time
    var deferral = e.Request.GetDeferral();

    StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(sender.FileName, CreationCollisionOption.ReplaceExisting);

    // Set update info for the file
    CachedFileUpdater.SetUpdateInformation(file, "CachedFile", ReadActivationMode.NotNeeded, WriteActivationMode.AfterWrite, CachedFileOptions.RequireUpdateOnAccess);

    // Assign the resulting file to the targetFile property and complete the deferral to indicate success  
    e.Request.TargetFile = file;
    deferral.Complete();
}
function onTargetFileRequested(e) {
    var deferral;
    deferral = e.request.getDeferral();

    Windows.Storage.ApplicationData.current.localFolder.createFileAsync(fileSavePickerUI.fileName, Windows.Storage.CreationCollisionOption.replaceExisting).done(
        function (file) {
            // Set update info for the file
            Windows.Storage.Provider.CachedFileUpdater.setUpdateInformation(
                file,
                "CachedFile",
                Windows.Storage.Provider.ReadActivationMode.notNeeded,
                Windows.Storage.Provider.WriteActivationMode.afterWrite,
                Windows.Storage.Provider.CachedFileOptions.requireUpdateOnAccess
            );

            // Assign the resulting file to the targetFile property and complete the deferral to indicate success
            e.request.targetFile = file;
            deferral.complete();
        }, function () {
            // Set the targetFile property to null and complete the deferral to indicate failure
            e.request.targetFile = null;
            deferral.complete();
        }
    );
};

Remarks

Access methods in this class statically.

Methods

SetUpdateInformation(IStorageFile, String, ReadActivationMode, WriteActivationMode, CachedFileOptions) SetUpdateInformation(IStorageFile, String, ReadActivationMode, WriteActivationMode, CachedFileOptions) SetUpdateInformation(IStorageFile, String, ReadActivationMode, WriteActivationMode, CachedFileOptions) SetUpdateInformation(IStorageFile, String, ReadActivationMode, WriteActivationMode, CachedFileOptions)

Configures update policies for a local file.

public : static void SetUpdateInformation(IStorageFile file, PlatForm::String contentId, ReadActivationMode readMode, WriteActivationMode writeMode, CachedFileOptions options)public static void SetUpdateInformation(IStorageFile file, String contentId, ReadActivationMode readMode, WriteActivationMode writeMode, CachedFileOptions options)Public Static Function SetUpdateInformation(file As IStorageFile, contentId As String, readMode As ReadActivationMode, writeMode As WriteActivationMode, options As CachedFileOptions) As void// You can use this method in JavaScript.
Parameters
contentId
PlatForm::String String String String

A unique identifier for the local file.

You can use this identifier to associate a file in your app's repository with the local file. When updates are requested by Windows, you can use this contentId to identify the correct file in your app's repository.

readMode
ReadActivationMode ReadActivationMode ReadActivationMode ReadActivationMode

A value that specifies whether Windows will request updates before the local file is read by other apps.

writeMode
WriteActivationMode WriteActivationMode WriteActivationMode WriteActivationMode

A value that specifies whether other apps can write to the local file and, if so, whether Windows will request updates after the local file is written.

options
CachedFileOptions CachedFileOptions CachedFileOptions CachedFileOptions

A value that specifies additional circumstances and behaviors for when Windows requests updates.

For example, you could require Windows to request an update every time the local file is accessed by using CachedFileOptions.RequireUpdateOnAccess. For more information about possible options, see CachedFileOptions.

Remarks

In order to use this method your app must participate in the Cached File Updater contract.

You can use this method to control how other apps can access a file that is provided by your app and to control when Windows requests updates for that file.

See Also