2

I am implementing Azure In-Role Caching for a Web API Web Role that I have. I would like to be able to Cache the BlobReference for specific blobs that do not change often. Here is the code I am using to get the BlobReference. The items I am getting are zip files that are of type CloudBlockBlob

public ICloudBlob GetBlob(string containerName, string blobName)
{
   CloudBlobContainer container = GetBlockBlobContainer(containerName);
   ICloudBlob blob = container.GetBlobReferenceFromServer(blobName);
   return blob;
}

However when I try to Put the item in Cache, it says that CloudBlockBlob is not serializable. Since I cannot modify that class to be serializable, is there a work-around for this? If not, what is the preferred method to cache the blob metadata for blobs that do not change often?

4

1 回答 1

1

将您需要的内容复制到 DTO 中。将复杂对象放入 appdomain 全局数据结构中通常不是一个好的模式。你永远不知道它们背后是什么样的对象图以及它们是否是线程安全的。如果课程来自第 3 方库,您将无法知道里面有什么。您需要自己控制对象。

长期运行的进程中的全局状态是非常关键的资源。如果您弄乱了应用程序,则在手动重新启动进程之前可能无法使用,这是灾难性的。

于 2015-11-12T20:58:42.313 回答