2010-06-22 37 views
0

我正在使用SharePoint Foundation 2010,並希望爲某些頁面或可能整個站點啓用輸出緩存。在SharePoint Server上,您有一種機制來在網站集中啓用頁面輸出緩存(實際上它實際上是ASP.NET輸出緩存)。在SPF上你不會得到這個功能 - 夠公平的。如何在SharePoint Foundation中啓用輸出緩存?

那麼如何啓用輸出緩存?在ASP.NET中,我只需添加頁面指令 - 類似<%@ OutputCache Duration =「30」%>。如果在頁面中,SharePoint會引發錯誤。聽起來它需要在代碼中完成,也許會覆蓋頁面類?歡迎任何建議。

回答

0

您需要進入頂級網站集,那裏您可以選擇網站管理 - >網站集輸出兌現 - >類似現金配置文件。在那裏你可以設置你的個人資料輸出兌現和其他東西。

0

你必須:

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