如何在 SharePoint Foundation 中启用输出缓存?

发布于 2024-09-07 01:20:56 字数 297 浏览 3 评论 0原文

我正在使用 SharePoint Foundation 2010,并且希望为某些页面或整个网站启用输出缓存。在 SharePoint Server 上,您有一种机制可以跨网站集启用页面输出缓存(它实际上是底层的 ASP.NET 输出缓存)。在 SPF 上你无法获得这个功能——这很公平。

那么如何启用输出缓存呢?在 ASP.NET 中,我只需添加一个页面指令 - 类似于 <%@ OutputCache Duration="30" %>。如果该内容位于页面中,SharePoint 会引发错误。听起来好像需要在代码中完成,也许覆盖页面类?欢迎任何建议。

I am using SharePoint Foundation 2010 and would like to enable output caching for certain pages, or maybe the whole site. On SharePoint Server you have a mechanism to enable page output caching across the site collection (it is actually ASP.NET output cache under the hood). On SPF you don't get that feature - fair enough.

So how can I enable output caching? In ASP.NET I would just add a page directive - something like <%@ OutputCache Duration="30" %>. SharePoint throws an error if this is in the page. Sounds like it needs to be done in code, perhaps override the page class? Any suggestions welcome.

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

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

发布评论

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

评论(2

苏别ゝ 2024-09-14 01:20:56

您需要进入顶部网站集,您可以在网站管理下选择->网站集输出兑现->诸如现金档案之类的东西。在那里您可以设置输出兑现和其他内容的配置文件。

You need to go on top site collection, there you have option under site administration->site collection output cashing-> something like cash profiles. There you can set your profile for output cashing and other stuff.

囍笑 2024-09-14 01:20:56

您必须:

0 - 添加参数

<%@ OutputCache Duration="300" VaryByParam="*" Shared="True" VaryByCustom="x"  VaryByControl="hdnButtonToForceUpdateCacheIfYouWantOnClick" %>

1 - 扩展 SPHttpApplication、IVaryByCustomHandler。

public class MyCache: SPHttpApplication, IVaryByCustomHandler {
public override void Init()
        {
            base.Init();
            this.RegisterGetVaryByCustomStringHandler((Microsoft.SharePoint.ApplicationRuntime.IVaryByCustomHandler)this);
        }

        public string GetVaryByCustomString(HttpApplication app, HttpContext context, string custom)
        {
            StringBuilder sb = new StringBuilder();

 string[] strings = custom.Split(';');
            bool appended = false;
            foreach (string str in strings)
            {
                switch (str)
                {
                     case "x":
                         var xv= context.Request.Cookies.Get("x");
                        if (xv!= null)
                        {
                            sb.Append(xv.Value);
                        }

                        break;
                }
             }
             return sb.toString();
           }
   }

2 - 修改您的 global.asax 后,

<%@ Assembly Name="Microsoft.SharePoint"%>
<%@ Assembly Name="Energisa.Distribuidora.Webparts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e2d241931dc35e9d"%> 
<%@ Import Namespace="(Namespace).Webparts" %>
<%@ Application Language="C#" Inherits="(Namespace).MyCache" %>

请参阅更多信息: https://msdn.microsoft.com/en-us/library/office/ms550239(v=office.14).aspx

You have to:

0 - Add the parameter

<%@ OutputCache Duration="300" VaryByParam="*" Shared="True" VaryByCustom="x"  VaryByControl="hdnButtonToForceUpdateCacheIfYouWantOnClick" %>

1 - Extend SPHttpApplication, IVaryByCustomHandler.

public class MyCache: SPHttpApplication, IVaryByCustomHandler {
public override void Init()
        {
            base.Init();
            this.RegisterGetVaryByCustomStringHandler((Microsoft.SharePoint.ApplicationRuntime.IVaryByCustomHandler)this);
        }

        public string GetVaryByCustomString(HttpApplication app, HttpContext context, string custom)
        {
            StringBuilder sb = new StringBuilder();

 string[] strings = custom.Split(';');
            bool appended = false;
            foreach (string str in strings)
            {
                switch (str)
                {
                     case "x":
                         var xv= context.Request.Cookies.Get("x");
                        if (xv!= null)
                        {
                            sb.Append(xv.Value);
                        }

                        break;
                }
             }
             return sb.toString();
           }
   }

2 - After modify your global.asax,

<%@ Assembly Name="Microsoft.SharePoint"%>
<%@ Assembly Name="Energisa.Distribuidora.Webparts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e2d241931dc35e9d"%> 
<%@ Import Namespace="(Namespace).Webparts" %>
<%@ Application Language="C#" Inherits="(Namespace).MyCache" %>

See more in: https://msdn.microsoft.com/en-us/library/office/ms550239(v=office.14).aspx

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