在@DotNetNuclear 的帮助下,构建了以下解决方案并发现它可以显着提高性能:
将 DNN 服务器上的 Default.aspx.cs 更改为首先确保所有未经身份验证的用户在其响应标头中都有 NoCache。并且经过身份验证的用户具有如下可缓存性设置:
Response.Cache.SetCacheability(HttpCacheability.NoCache); // You can set host settings to 0. Is the same.
}
else
{
// Unauthenticated users.
// MAKE CONFIGURABLE IN HOST SETTINGS.
Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
//
// Allow proxies to cache for one day.
//
// MAKE CONFIGURABLE IN HOST SETTINGS.
Response.Cache.SetProxyMaxAge(new TimeSpan(24, 0, 0));
//
// Enforce not caching at client.
//
// MAKE CONFIGURABLE IN HOST SETTINGS.
Response.Cache.SetMaxAge(new TimeSpan(0, 0, 30));
}
已记录请求以允许最终用户配置这些更改。现在,您可以使用 Apache 中的以下设置来区分经过身份验证的 (NoCache) 和未经身份验证的/公共请求 (ServerAndPrivate):
CacheEnable disk /
CacheRoot /var/cache/mod_cache
CacheDirLevels 2
CacheDirLength 4
# Do not overrule the default settings whether to cache.
# Can not be off, sorry.
CacheIgnoreNoLastMod on
#
# Use ServerAndPrivate since otherwise the Set-Cookie makes the cache
# being unused.
#
CacheStorePrivate on
CacheStoreNoStore on
#
# Ensure you set authenticatedcacheability on server to NoCache.
#
# Set to this off to allow logins.
CacheIgnoreCacheControl off
#
CacheIgnoreQueryString off
#
# Avoid cookies being put in cache.
# Use removal of the Server header as a sign that something is coming from cache.
# It requires Apache 2.4 to indicate that more nicely.
#
CacheIgnoreHeaders Set-Cookie Server
#
# Cache by default when not specified otherwise in last-modified or expiry date.
# In seconds.
CacheDefaultExpire 86400
CacheMaxFileSize 100000
#
# Always check every two days.
#
CacheMaxExpire 172800
# Disable caching on locations which we know to contain static content already
# cached by IIS.
CacheDisable ...some locations...
#
# Rewrite DNN caching.
#
#
# Set public instead of no-cache cahing on these specific files. IIS wants to
# use with max-age but without public. Probably since a cookie is involved, but that
# cookie is cleaned away in the cache.
#
SetEnvIfNoCase Request_URI "DependencyHandler\.axd$" rewrite_to_public_cache
SetEnvIfNoCase Request_URI "sb-client\.js$" rewrite_to_public_cache
SetEnvIfNoCase Request_URI "main\.js$" rewrite_to_public_cache
SetEnvIfNoCase Request_URI "inpage_linkid\.js$" rewrite_to_public_cache
SetEnvIfNoCase Request_URI "\.gif$" rewrite_to_public_cache
SetEnvIfNoCase Request_URI "\.png$" rewrite_to_public_cache
SetEnvIfNoCase Request_URI "\.jpg$" rewrite_to_public_cache
Header edit Cache-Control no-cache public env=rewrite_to_public_cache