在 SharePoint Server 中設定 web 應用程式的快取設定Configure cache settings for a web application in SharePoint Server

摘要:了解如何設定 BLOB 快取、 頁面輸出快取設定檔及物件快取的 web 應用程式。Summary: Learn how to configure the BLOB cache, page output cache profiles, and the object cache for a web application.

本文說明如何在 SharePoint Server 2016 與 SharePoint Server 2013 中設定磁碟 BLOB 快取、 頁面輸出快取設定檔及物件快取的 web 應用程式。This article describes how to configure the disk-based BLOB cache, the page output cache profiles, and the object cache for a web application in SharePoint Server 2016 and SharePoint Server 2013.

您要在要套用那些變更之 Web 應用程式的 Web.config 檔案中啟用和設定 BLOB 快取、變更頁面輸出快取設定檔及物件快取的組態。您對 Web.config 檔案進行的變更將套用至 Web 應用程式內所有網站集合。You enable and configure the BLOB cache, and make configuration changes to the page output cache profiles and the object cache in the Web.config file in the web application to which you want to apply those changes. The changes you make to the Web.config file will be applied to all site collections within the web application.

SharePoint Server 包含可讓您確認伺服器陣列快取設定正確無誤和快取的最大效能執行的快取效能監視器。如需詳細資訊,請參閱 <在 SharePoint Server 2016 監視快取效能SharePoint Server includes cache performance monitors that let you verify that the farm cache settings are correct and that the caching is running at maximum performance. For more information, see Monitor cache performance in SharePoint Server 2016.

注意

在 Web 應用程式層級設定頁面輸出快取設定檔與物件快取會取代網站管理員在網站集合層級或以下所設定的任何組態。Configuring the page output cache profiles and the object cache at the web application level will supersede any configuration that was made by site administrators at the site collection level or below.

提示

可能的 BLOB 快取變成與該內容同步處理時的時間。例如,還原內容資料庫之後,BLOB 快取會與該內容同步處理。若要修正的情況下,您必須清除 BLOB 快取。如需詳細資訊,請參閱清除 BLOB 快取 in SharePoint ServerThere may be times when the BLOB cache becomes out of sync with the content. For example, after you restore a content database, the BLOB cache will be out of sync with the content. To correct that situation, you must flush the BLOB cache. For more information, see Flush the BLOB cache in SharePoint Server.

如需詳細資訊,請參閱 < SharePoint Server 中的快取設定操作For more information, see Cache settings operations in SharePoint Server.

設定 BLOB 快取設定Configure BLOB cache settings

磁碟式 BLOB 快取預設為已關閉,如果您要使用,則必須從前端網頁伺服器開啟。請使用下列程序來設定 Web 應用程式的磁碟式快取設定。By default, the disk-based BLOB cache is off and must be enabled on the front-end web server if you want to use it. Use the following procedure to configure disk-based cache settings for a web application.

重要

變更 web.config 檔案之前,請使用不同的名稱 (例如 web.config1) 建立檔案複本,以便檔案發生錯誤時可以還原原始檔案。Before you make changes to the web.config file, make a copy of it by using a different name (for example, web.config1), so that if a mistake is made in the file, you can restore the original file.

設定 BLOB 快取設定To configure BLOB cache settings

  1. 確認是否具備下列系統管理認證:您必須是本機電腦 Administrators 群組的成員,才能夠設定 BLOB 快取設定。Verify that you have the following administrative credentials: You must be a member of the Administrators group on the local computer to configure the BLOB cache settings.

  2. 開啟 [伺服器管理員]、 [工具] 和 [網際網路資訊服務 (IIS) 管理員]Open Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.

  3. 在網際網路資訊服務 (IIS) 管理員] 中,在 [連線] 窗格中,展開包含之 web 應用程式的伺服器名稱,然後展開來檢視已建立的應用程式的 web 應用程式的網站In Internet Information Services (IIS) Manager, in the Connections pane, expand the server name that contains the web application, and then expand Sites to view the web application or applications that have been created.

  4. 以滑鼠右鍵按一下您要設定的磁碟快取的 web 應用程式的名稱並再按一下 [瀏覽。開啟 Windows 檔案總管與所選的 web 應用程式所列的目錄。Right-click the name of the web application for which you want to configure the disk-based cache, and then click Explore. Windows Explorer opens, with the directories for the selected web application listed.

  5. 在 [開啟] 對話方塊中,按一下[記事本] 中,並再按一下 [確定]In the Open With dialog box, click Notepad, and then click OK.

  6. 在 web.config [記事本] 檔案中,尋找下行:<BlobCache location="C:\BlobCache\14" path="\.(gif|jpg|jpeg|jpe|jfif|bmp|dib|tif|tiff|themedbmp|themedcss|themedgif|themedjpg|themedpng|ico|png|wdp|hdp|css|js|asf|avi|flv|m4v|mov|mp3|mp4|mpeg|mpg|rm|rmvb|wma|wmv|ogg|ogv|oga|webm|xap)$" maxSize="10" enabled="false" />In the web.config Notepad file, find the following line: <BlobCache location="C:\BlobCache\14" path="\.(gif|jpg|jpeg|jpe|jfif|bmp|dib|tif|tiff|themedbmp|themedcss|themedgif|themedjpg|themedpng|ico|png|wdp|hdp|css|js|asf|avi|flv|m4v|mov|mp3|mp4|mpeg|mpg|rm|rmvb|wma|wmv|ogg|ogv|oga|webm|xap)$" maxSize="10" enabled="false" />

    當使用影像轉譯為 40 個巨型像素映像預設最大大小。您要修改此才能新增 imageRenditionMaxSourcePixels 參數的值應。例如:<BlobCache location="C:\BlobCache\14" path="\.(gif|jpg|jpeg|jpe|jfif|bmp|dib|tif|tiff|themedbmp|themedcss|themedgif|themedjpg|themedpng|ico|png|wdp|hdp|css|js|asf|avi|flv|m4v|mov|mp3|mp4|mpeg|mpg|rm|rmvb|wma|wmv|ogg|ogv|oga|webm|xap)$" maxSize="10" imageRenditionMaxSourcePixels="100000000" enabled="true" />這會設定能夠在大約 100 巨型像素的影像轉譯大小的最大的影像。The default max size for an image when using Image Renditions is 40 mega pixels. Should you want to modify this value you will need to add the imageRenditionMaxSourcePixels parameter. For example: <BlobCache location="C:\BlobCache\14" path="\.(gif|jpg|jpeg|jpe|jfif|bmp|dib|tif|tiff|themedbmp|themedcss|themedgif|themedjpg|themedpng|ico|png|wdp|hdp|css|js|asf|avi|flv|m4v|mov|mp3|mp4|mpeg|mpg|rm|rmvb|wma|wmv|ogg|ogv|oga|webm|xap)$" maxSize="10" imageRenditionMaxSourcePixels="100000000" enabled="true" /> This will set the max image size for Image Renditions to work at around 100 mega pixels.

  7. 在這一行中,變更location屬性以指定具有足夠空間可容納快取大小的目錄。In this line, change the location attribute to specify a directory that has enough space to accommodate the cache size.

    注意

    強烈建議您要指定儲存伺服器作業系統交換檔或伺服器記錄檔所在相同磁碟上的目錄。We strongly recommend that you specify a directory that is not on the same drive as where either the server operating system swap files or server log files are stored.

  8. 若要新增或移除,快取的檔案類型清單的檔案類型的path屬性、 修改的規則運算式以包含或移除適當的副檔名。若您要新增的副檔名,請務必使用管道 (|) 分隔每個檔案類型,這一行程式碼所示。To add or remove file types from the list of file types to be cached, for the path attribute, modify the regular expression to include or remove the appropriate file extension. If you add file extensions, make sure to separate each file type with a pipe (|), as shown in this line of code.

  9. 若要變更的快取大小,輸入新號碼maxSize。大小以十億位元組 (GB) 及預設值是 10 GB。To change the size of the cache, type a new number for maxSize. The size is expressed in gigabytes (GB), and 10 GB is the default.

    重要

    建議您不要設定快取大小小於 10 GB。當您設定的快取大小時,請務必指定足以提供緩衝區大於會儲存在快取的內容的估計大小至少 20%的數字。It is recommended that you not set the cache size smaller than 10 GB. When you set the cache size, make sure to specify a number large enough to provide a buffer at least 20 percent bigger than the estimated size of the content that will be stored in the cache.

  10. 若要啟用 BLOB 快取,請變更enabled屬性,從"false""true"To enable the BLOB cache, change the enabled attribute, from "false" to "true".

  11. 儲存記事本檔案,然後關閉。Save the Notepad file, and then close it.

警告

如果將變更儲存至 web.config 檔案,則自動回收網際網路資訊服務 (IIS) 7.0 中的 web 應用程式。此回收導致短暫中斷服務以該 web 應用程式中所包含的網站和使用者可能會遺失工作階段狀態。如需回收 IIS 7.0 中的 web 應用程式的資訊,請參閱IIS 處理序回收When you save a change to the web.config file, the web application in Internet Information Services (IIS) 7.0 automatically recycles. This recycling can cause a brief interruption in service to sites contained in that web application, and users can lose session state. For information about recycling web applications in IIS 7.0, see IIS Process Recycling.

設定快取設定檔設定Configure cache profile settings

快取設定檔設定可由網站集合管理員透過使用者介面在網站集合層級設定,以及由管理員以 Web 應用程式層級在前端網頁伺服器上設定。必須先在網站集合層級啟用頁面輸出快取,才能夠在網站集合層級或 Web 應用程式層級設定頁面輸出快取設定檔。如果頁面輸出快取設定檔是在 Web 應用程式層級啟用,Web.config 中指定的設定值將用於所有頁面輸出快取設定檔,並會置換透過使用者介面在網站集合層級輸入的任何值。Cache profile settings can be configured in the user interface at the site collection level by a site collection administrator, as well as at the web application level by an administrator on the front-end web server. The page output cache must be enabled at the site collection level before page output cache profiles can be configured at either the site collection level or web application level. If page output cache profiles are enabled at the web application level, the settings specified in Web.config will be used for all page output cache profiles, overriding any values that have been entered through the user interface at the site collection level.

注意

若要使用網頁輸出快取和相關的快取設定檔設定,您必須使用網站上的發佈功能。To use the page output cache and the associated cache profile settings, you must be using the Publishing feature on your site.

注意

有內容搜尋網頁組件的已知的問題。在 [網頁組件中的 SendContentBeforeQuery 設定不適用於正確使用輸出快取的頁面。在 SharePoint Server 2013 累計更新 3 月 2013 解決這個問題。如需詳細資訊,請參閱 Microsoft 知識庫文章 2767999:說明 SharePoint Server 2013 更新: 2013 年 3 月 12 日There is a known issue with the Content Search Web Part. The SendContentBeforeQuery setting in the Web Part does not work correctly on pages that use output caching. This issue is resolved in the SharePoint Server 2013 cumulative update for March 2013. For more information, see Microsoft Knowledge Base article 2767999: Description of the SharePoint Server 2013 update: March 12, 2013.

請使用下列程序設定 Web 應用程式的快取設定檔設定。Use the following procedure to configure the cache profile settings for a web application.

重要

變更 web.config 檔案之前,請使用不同的名稱 (例如 web.config1) 建立檔案複本,以便檔案發生錯誤時可以還原原始檔案。Before you make changes to the web.config file, make a copy of it by using a different name (for example, web.config1), so that if a mistake is made in the file, you can restore the original file.

若要設定網頁輸出快取設定檔設定To configure page output cache profile settings

  1. 確認是否具備下列系統管理認證:您必須是本機電腦 Administrators 群組的成員,才能夠設定快取設定檔設定。Verify that you have the following administrative credentials: You must be a member of the Administrators group on the local computer to configure the cache profile settings.

  2. 開啟 [伺服器管理員]、 [工具] 和 [網際網路資訊服務 (IIS) 管理員]Open Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.

  3. 在網際網路資訊服務 (IIS) 管理員] 中,在 [連線] 窗格中,展開包含之 web 應用程式的伺服器名稱,然後展開來檢視已建立的應用程式的 web 應用程式的網站In Internet Information Services (IIS) Manager, in the Connections pane, expand the server name that contains the web application, and then expand Sites to view the web application or applications that have been created.

  4. 以滑鼠右鍵按一下您要設定的磁碟快取的 web 應用程式的名稱並再按一下 [瀏覽。開啟 Windows 檔案總管與所選的 web 應用程式所列的目錄。Right-click the name of the web application for which you want to configure the disk-based cache, and then click Explore. Windows Explorer opens, with the directories for the selected web application listed.

  5. 以滑鼠右鍵按一下web.config,按一下 [開啟並選擇[記事本]如果詢問您找出要用來開啟此檔案的程式。Right-click web.config, click Open and choose Notepad if you're asked to find a program to use to open this file.

  6. 在 web.config [記事本] 檔案中,尋找下行:<OutputCacheProfiles useCacheProfileOverrides="false" varyByHeader="" varyByParam="*" varyByCustom="" varyByRights="true" cacheForEditRights="false" />In the web.config Notepad file, find the following line: <OutputCacheProfiles useCacheProfileOverrides="false" varyByHeader="" varyByParam="*" varyByCustom="" varyByRights="true" cacheForEditRights="false" />

  7. 若要啟用 web 應用程式層級的快取設定檔,請變更useCacheProfileOverrides屬性,從"false""true"To enable the cache profile at the web application level, change the useCacheProfileOverrides attribute, from "false" to "true".

    注意

    如果您將此值設為 true,Web.config 中指定的設定值將用於所有頁面輸出快取設定檔。此值會覆寫透過使用者介面在網站集合層級輸入的任何值。If you set this to true the settings specified in Web.config will be used for all page output cache profiles. This overrides any values that have been entered through the user interface at the site collection level.

  8. 若要覆寫varyByHeader屬性中,輸入.NET Framework Class Library 項目HttpCachePolicy.VaryByHeaders 屬性中所指定的自訂參數。To override the varyByHeader attribute, type a custom parameter as specified in the .NET Framework Class Library entry HttpCachePolicy.VaryByHeaders Property.

  9. 若要覆寫varyByParam屬性中,輸入.NET Framework Class Library 項目HttpCachePolicy.VaryByParams 屬性中所指定的自訂參數。To override the varyByParam attribute, type a custom parameter as specified in the .NET Framework Class Library entry HttpCachePolicy.VaryByParams Property.

  10. 若要覆寫varyByCustom屬性中,輸入.NET Framework Class Library 項目HttpCachePolicy.SetVaryByCustom 方法中所指定的自訂參數。To override the varyByCustom attribute, type a custom parameter as specified in the .NET Framework Class Library entry HttpCachePolicy.SetVaryByCustom Method.

  11. 若要覆寫varyByRights屬性、 變更從值"true""false"。這會移除使用者必須對如其他使用者一樣看見相同的快取] 頁面上的所有安全的物件擁有相同的有效權限需求。To override the varyByRights attribute, change the value from "true" to "false". This will remove the requirement that users must have identical effective permissions on all securable objects to see the same cached page as any other user.

  12. 若要覆寫cacheForEditRights屬性、 變更cacheForEditRights屬性,從"false""true"。這將會略過具有編輯人員擁有權限快取其頁面時之正常行為。To override the cacheForEditRights attribute, change the cacheForEditRights attribute, from "false" to "true". This will bypass the normal behavior in which people with edit permissions have their pages cached.

  13. 儲存記事本檔案,然後關閉。Save the Notepad file, and then close it.

警告

如果將變更儲存至 web.config 檔案,則自動回收網際網路資訊服務 (IIS) 7.0 中的 web 應用程式。此回收導致短暫中斷服務以該 web 應用程式中所包含的網站和使用者可能會遺失工作階段狀態。如需回收 IIS 7.0 中的 web 應用程式的資訊,請參閱啟動或停止網頁伺服器 (IIS 8)When you save a change to the web.config file, the web application in Internet Information Services (IIS) 7.0 automatically recycles. This recycling can cause a brief interruption in service to sites contained in that web application, and users can lose session state. For information about recycling web applications in IIS 7.0, see Start or Stop the Web Server (IIS 8).

設定物件快取設定Configure object cache settings

物件快取設定可在網站集合層級使用者介面中設定網站集合管理員,並根據預設值。可以在 web 應用程式層級上的所有網站集合將會都使用快取的記憶體數量上限放置限制前端網頁伺服器上設定的最大快取大小。例如,個別網站集合可能會有物件快取設定為 100 MB 時可能會在 1 GB 設定 web 應用程式。在此例中的伺服器上的所有快取要使用不超過 1 GB 的記憶體。The object cache settings can be configured at the site collection level in the user interface by a site collection administrator, and is on by default. The maximum cache size can be configured at the web application level on the front-end web server to place a restriction on the maximum amount of memory that the cache will use for all site collections. For example, individual site collections might have the object cache set at 100 MB, while the web application might be set at 1 GB. In this case, no more than 1 GB of memory will be used by all the caches on the server.

注意

若要使用物件快取,您必須使用網站上的發佈功能。To use the object cache, you must be using the Publishing feature on your site.

請使用下列程序,在前端網頁伺服器上設定 Web 應用程式的物件快取設定。Use the following procedure to configure the object cache settings for a web application on a front-end web server.

重要

變更 web.config 檔案之前,請使用不同的名稱 (例如 web.config1) 建立檔案複本,以便檔案發生錯誤時可以還原原始檔案。Before you make changes to the web.config file, make a copy of it by using a different name (for example, web.config1), so that if a mistake is made in the file, you can restore the original file.

若要設定物件快取設定To configure object cache settings

  1. 確認是否具備下列系統管理認證:您必須是本機電腦 Administrators 群組的成員,才能夠設定物件快取設定。Verify that you have the following administrative credentials: You must be a member of the Administrators group on the local computer to configure the object cache settings.

  2. 開啟 [伺服器管理員]、 [工具] 和 [網際網路資訊服務 (IIS) 管理員]Open Server Manager, click Tools, and then click Internet Information Services (IIS) Manager.

  3. 在網際網路資訊服務 (IIS) 管理員] 中,在 [連線] 窗格中,展開包含之 web 應用程式的伺服器名稱,然後展開來檢視已建立的應用程式的 web 應用程式的網站In Internet Information Services (IIS) Manager, in the Connections pane, expand the server name that contains the web application, and then expand Sites to view the web application or applications that have been created.

  4. 以滑鼠右鍵按一下您要設定的磁碟快取的 web 應用程式的名稱並再按一下 [瀏覽。開啟 Windows 檔案總管與所選的 web 應用程式所列的目錄。Right-click the name of the web application for which you want to configure the disk-based cache, and then click Explore. Windows Explorer opens, with the directories for the selected web application listed.

  5. 以滑鼠右鍵按一下web.config、 按一下 [開啟] 並選取[記事本]如果詢問您找出要用來開啟此檔案的程式。Right-click web.config, click Open and select Notepad if you're asked to find a program to use to open this file.

  6. 在 Web.config [記事本] 檔案中,尋找下行:<ObjectCache maxSize="100" />In the Web.config Notepad file, find the following line: <ObjectCache maxSize="100" />

  7. 若要變更的快取大小,輸入新號碼maxSize。大小 (mb) 以表示為及 100 MB 是預設值。To change the size of the cache, type a new number for maxSize. The size is expressed in megabytes (MB), and 100 MB is the default.

  8. 儲存記事本檔案,然後關閉。Save the Notepad file, and then close it.

警告

如果將變更儲存至 web.config 檔案,則自動回收網際網路資訊服務 (IIS) 7.0 中的 web 應用程式。此回收導致短暫中斷服務以該 web 應用程式中所包含的網站和使用者可能會遺失工作階段狀態。如需回收 IIS 7.0 中的 web 應用程式的資訊,請參閱啟動或停止網頁伺服器 (IIS 8)When you save a change to the web.config file, the web application in Internet Information Services (IIS) 7.0 automatically recycles. This recycling can cause a brief interruption in service to sites contained in that web application, and users can lose session state. For information about recycling web applications in IIS 7.0, see Start or Stop the Web Server (IIS 8).

另請參閱See also

概念Concepts

Cache settings operations in SharePoint ServerCache settings operations in SharePoint Server

在 SharePoint Server 中規劃快取及效能Plan for caching and performance in SharePoint Server