EWS托管API同步缓存位置

本文关键字:缓存 位置 同步 API 托管 EWS | 更新日期: 2023-09-27 18:18:58

当使用Exchange Web Services (EWS) Managed API同步文件夹层次结构或同步项时,客户端缓存位于何处?它只在内存中吗?它在磁盘上吗?有没有办法找到或控制缓存的位置?

EWS托管API同步缓存位置

SyncFolderHierarchySyncFolderItems一起允许您有效地同步Exchange中邮箱中所有(或一部分)文件夹的内容。

文章中指示的流程是指示性的。对SyncFolderItems的调用返回ChangeCollection<T>,其中包含ItemChangeFolderChange类型的项。如果要处理这些项目,则可以拉下文件夹上的附加信息,或者例如文件夹中每个项目的实际内容。

在处理完ChangeCollection之后,应该将SyncState的值存储在某个地方。下次调用SyncFolderItems时,传入该值,Exchange将返回下一批物品。

因为很可能(尤其是第一次同步时)在单个调用中有比SyncFolderItems可以返回的项目更多的项目,您应该检查MoreChangesAvailable以确定是否还有更多的事情要做。

所有这些都变成了这个循环:

// Track whether there are more items available for download on the server.
bool moreChangesAvailable = false;
do {
    // Get a list of all items in the Inbox by calling SyncFolderHierarchy repeatedly until no more changes are available.
    // The folderId parameter must be set to the root folder to synchronize,
    // and must be same folder ID as used in previous synchronization calls. 
    // The propertySet parameter is set to IdOnly to reduce calls to the Exchange database,
    // because any additional properties result in additional calls to the Exchange database. 
    // The ignoredItemIds parameter is set to null, so that no items are ignored.
    // The maxChangesReturned parameter is set to return a maximum of 10 items (512 is the maximum).
    // The syncScope parameter is set to Normal items, so that associated items will not be returned.
    // The syncState parameter is set to cSyncState, which should be null in the initial call, 
    // and should be set to the sync state returned by the 
    // previous SyncFolderItems call in subsequent calls.
    ChangeCollection<ItemChange> icc = service.SyncFolderItems(new FolderId(WellKnownFolderName.Inbox), PropertySet.IdOnly, null, 10, SyncFolderItemsScope.NormalItems, cSyncState);
    // If the count of changes is zero, there are no changes to synchronize.
    if (icc.Count <> 0) {
        // Otherwise, write all the changes included in the response to the console. 
        foreach (ItemChange ic in icc) {
            Console.WriteLine("ChangeType: " + ic.ChangeType.ToString());
            Console.WriteLine("ItemId: " + ic.ItemId);
        }
    }
    // Save the sync state for use in future SyncFolderContent requests.
    // The sync state is used by the server to determine what changes to report
    // to the client.
    string sSyncState = icc.SyncState;
   // Determine whether more changes are available on the server.
   moreChangesAvailable = icc.MoreChangesAvailable;
}
while (moreChangesAvailable);

来自MSDN的代码示例,因为我不能说得比他们更好

所以没有客户端缓存这种东西,除非您选择自己在客户端存储项目。如果您选择不存储它们,您可以简单地继续循环,直到到达您感兴趣的内容开始的点。例如,上面的代码不下载任何东西,除了ItemChange记录和每个项目的ID(由PropertySet.IdOnly表示)。

这篇MSDN文章提供了同步过程的一个很好的概述