我想知道,如果我可以將Plist和Images的zip文件存儲在AppFabric緩存中嗎?如果是,如何?我們是否需要將zip文件轉換爲二進制格式或其他格式,以便它可以存儲在App Fabric中。可以將zip文件和圖像存儲在AppFabric緩存中
我正在考慮將整個zip內容存儲在AppFabric緩存中,以便改進我的應用程序的性能和可伸縮性。
我在.net c#中開發我的web服務。
我想知道,如果我可以將Plist和Images的zip文件存儲在AppFabric緩存中嗎?如果是,如何?我們是否需要將zip文件轉換爲二進制格式或其他格式,以便它可以存儲在App Fabric中。可以將zip文件和圖像存儲在AppFabric緩存中
我正在考慮將整個zip內容存儲在AppFabric緩存中,以便改進我的應用程序的性能和可伸縮性。
我在.net c#中開發我的web服務。
是的,您可以將這些文件存儲在AppFabric中 - AppFabric中存儲對象的限制是它們是serialisable(或serializable,如果您在美國:-))。如何將文件轉換爲可串行化的對象?你把它變成字節 - 這個例子允許你上傳帶有網頁的zip文件。
<asp:FileUpload runat="server" ID="ZipFileUpload" /><br />
<asp:Button runat="server" ID="UploadButton" Text="Upload file to AppFabric" OnClick="UploadButton_Click" />
<hr />
<asp:GridView runat="server" AutoGenerateColumns="false" ID="CachedZipFilesGridview">
<Columns>
<asp:BoundField DataField="Key" />
</Columns>
</asp:GridView>
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindGrid();
}
}
protected void UploadButton_Click(object sender, EventArgs e)
{
DataCacheFactory factory;
DataCache zipCache;
Byte[] zipArray;
// Check to see if the user uploaded a zip file
if (ZipFileUpload.HasFile && ZipFileUpload.PostedFile.FileName.EndsWith(".zip"))
{
// Initialise the byte array to the length of the uploaded file
zipArray = new Byte[ZipFileUpload.PostedFile.ContentLength];
// Read the uploaded file into the byte array
ZipFileUpload.PostedFile.InputStream.Read(zipArray, 0, ZipFileUpload.PostedFile.ContentLength);
factory = new DataCacheFactory();
// Get the "files" cache
zipCache = factory.GetCache("files");
// Add the byte array to the zipfiles region of the cache
// Using regions allows us to separate out images and zips
zipCache.Add(ZipFileUpload.PostedFile.FileName, zipArray,new TimeSpan(1,0,0), "zipfiles");
bindGrid();
}
}
protected void bindGrid()
{
DataCacheFactory factory;
DataCache zipCache;
IEnumerable<KeyValuePair<string, object>> cachedFiles;
DataTable cachedFilesDataTable;
factory = new DataCacheFactory();
zipCache = factory.GetCache("files");
cachedFiles = zipCache.GetObjectsInRegion("zipfiles");
cachedFilesDataTable = new DataTable();
cachedFilesDataTable.Columns.Add(new DataColumn("Key", typeof(string)));
foreach (KeyValuePair<string, object> cachedFile in cachedFiles)
{
cachedFilesDataTable.Rows.Add(cachedFile.Key);
}
CachedZipFilesGridview.DataSource = cachedFilesDataTable;
CachedZipFilesGridview.DataBind();
}
}
如果zip文件和圖像的內容沒有動態創建,爲什麼不使用iis緩存來緩存這些文件。 File Cache (IIS 6.0)