zip 文件和图像可以存储在 AppFabric 缓存中吗

发布于 2024-09-10 20:18:31 字数 208 浏览 6 评论 0原文

我想知道,我是否可以将 Plist 和 Images 的 zip 文件存储在 AppFabric 缓存中?如果是,怎么办?我们是否需要将 zip 文件转换为二进制格式或其他格式,以便将其存储在 App Fabric 中。

我正在考虑将整个 zip 内容存储在 AppFabric 缓存中,以便提高应用程序的性能和可扩展性。

我正在使用 .net c# 开发我的网络服务。

I would like to know, if i can store the zip files of Plist and Images in the AppFabric cache? If yes, how? Do we need to covert the zip files to binary format or some other format, so that it can be stored in the App Fabric.

I am looking at storing the entire zip content in the AppFabric cache , so that the performance and the scalibility of my application improves.

I am developing my web service in .net c#.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

灰色世界里的红玫瑰 2024-09-17 20:18:31

是的,您可以将这些文件存储在 AppFabric 中 - 在 AppFabric 中存储对象的限制是它们是 可序列化 (或 可序列化如果您在美国:-))。如何将文件转换为可序列化对象?您将其转换为字节 - 这是一个允许您使用网页上传 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();
    }
}

Yes, you can store these files in AppFabric - the restriction for storing objects in AppFabric is that they are serialisable (or serializable if you're in the USA :-)). How do you turn a file into a serialisable object? You turn it into bytes - here's an example that allows you to upload zip files with a web page.

<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();
    }
}
简单 2024-09-17 20:18:31

如果 zip 文件和图像的内容不是动态创建的,为什么不使用 iis 缓存来缓存这些文件。
文件缓存(IIS 6.0)

if the content of the zip files and images are not created dynamically why not use iis cache for caching these files.
File Cache (IIS 6.0)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文