< %@ OutputCache Duration="86400" Location="Sever"/>
可以为页面建立缓存,
但是当缓存时间比较长时,
如果在后台数据库有更改,并不能及时表现在页面上
请问有什么方法可以编程清除通过此指令缓存的数据?至少清除存于sever的缓存?
9 个解决方案
#1
其它缓存依赖项包括SqlDependency、VaryByControl、VaryByParam、VaryByCustomer等等。
Duration当然要设置一个比较长的值。因为当业务数据修改时,根本跟Duration没有关系,而是跟其它参数有关。你总不能张冠李戴地去纠结Duration参数。
Duration当然要设置一个比较长的值。因为当业务数据修改时,根本跟Duration没有关系,而是跟其它参数有关。你总不能张冠李戴地去纠结Duration参数。
#2
“编程清除通过此指令缓存”
自己好还是搞清楚应该用什么参数来设置,不要纠结在Duration上。
自己好还是搞清楚应该用什么参数来设置,不要纠结在Duration上。
#3
我只是想让数据库有更新操作时,能够及时重建缓存,对于Duration倒并不纠结
根据你刚才说的,才意识到用VaryByCustomer
现在我想用一个静态变量保存一个guid
当有数据库更新时,同时更新此guid
并重写 GetVaryByCustomString 方法,返回guid.ToString()
这样做可以吗?
#4
貌似不对啊
VaryByCustomer只能创建不同的缓存版本,并不是依赖于GetVaryByCustomString()的返回值。
VaryByCustomer只能创建不同的缓存版本,并不是依赖于GetVaryByCustomString()的返回值。
#5
从来没有关注过。
#6
跟数据库有关,你就该找数据库缓存依赖
#7
为了减小浏览器与服务器之间网络传输压力,往往对静态文件,如js,css,修饰的图片做cache,也就是给这些文件的HTTP响应头加入 Expires和Cache-Control参数,并指定缓存时间,这样一定时间内浏览器就不会给服务器发出任何的HTTP请求(除了强制刷新),即使在 这段时间内服务器的js或css或图片文件已经更新多次,但浏览器的数据依然是原来最能初cache的旧数据,有没有办法让浏览器拿到已经修改后的最新数 据呢?
有,方法是用ajax请求服务器最新文件,并加上请求头If-Modified-Since和Cache-Control,如下:
$.ajax({
type: "GET",
url: "static/cache.js",
dataType: "text",
beforeSend :function(xmlHttp){
xmlHttp.setRequestHeader("If-Modified-Since","0");
xmlHttp.setRequestHeader("Cache-Control","no-cache");
}
});
这里用了jquery.
这样浏览器就会把最新的文件替换掉本地旧文件。
当然,这里还一个问题就是js必须知道服务器更新了那个js、css、图片,利用cookie和时间版本应该可以解决.
jquery自从1.2开始就有ifModified和cache参数了,不用自己加header
ifModified Boolean Default: false
Allow the request to be successful only if the response has changed since the last request. This is done by checking the Last-Modified header. Default value is false, ignoring the header.
cache Boolean Default: true
Added in jQuery 1.2, if set to false it will force the pages that you request to not be cached by the browser.
$.ajax({
type: "GET",
url: "static/cache.js",
dataType: "text",
cache:false,
ifModified :true
});
有,方法是用ajax请求服务器最新文件,并加上请求头If-Modified-Since和Cache-Control,如下:
$.ajax({
type: "GET",
url: "static/cache.js",
dataType: "text",
beforeSend :function(xmlHttp){
xmlHttp.setRequestHeader("If-Modified-Since","0");
xmlHttp.setRequestHeader("Cache-Control","no-cache");
}
});
这里用了jquery.
这样浏览器就会把最新的文件替换掉本地旧文件。
当然,这里还一个问题就是js必须知道服务器更新了那个js、css、图片,利用cookie和时间版本应该可以解决.
jquery自从1.2开始就有ifModified和cache参数了,不用自己加header
ifModified Boolean Default: false
Allow the request to be successful only if the response has changed since the last request. This is done by checking the Last-Modified header. Default value is false, ignoring the header.
cache Boolean Default: true
Added in jQuery 1.2, if set to false it will force the pages that you request to not be cached by the browser.
$.ajax({
type: "GET",
url: "static/cache.js",
dataType: "text",
cache:false,
ifModified :true
});
#8
建立数据缓存,可以用Cache对象,用法和Session差不多。
#9
你这是清除客户端缓存
#1
其它缓存依赖项包括SqlDependency、VaryByControl、VaryByParam、VaryByCustomer等等。
Duration当然要设置一个比较长的值。因为当业务数据修改时,根本跟Duration没有关系,而是跟其它参数有关。你总不能张冠李戴地去纠结Duration参数。
Duration当然要设置一个比较长的值。因为当业务数据修改时,根本跟Duration没有关系,而是跟其它参数有关。你总不能张冠李戴地去纠结Duration参数。
#2
“编程清除通过此指令缓存”
自己好还是搞清楚应该用什么参数来设置,不要纠结在Duration上。
自己好还是搞清楚应该用什么参数来设置,不要纠结在Duration上。
#3
我只是想让数据库有更新操作时,能够及时重建缓存,对于Duration倒并不纠结
根据你刚才说的,才意识到用VaryByCustomer
现在我想用一个静态变量保存一个guid
当有数据库更新时,同时更新此guid
并重写 GetVaryByCustomString 方法,返回guid.ToString()
这样做可以吗?
#4
貌似不对啊
VaryByCustomer只能创建不同的缓存版本,并不是依赖于GetVaryByCustomString()的返回值。
VaryByCustomer只能创建不同的缓存版本,并不是依赖于GetVaryByCustomString()的返回值。
#5
从来没有关注过。
#6
跟数据库有关,你就该找数据库缓存依赖
#7
为了减小浏览器与服务器之间网络传输压力,往往对静态文件,如js,css,修饰的图片做cache,也就是给这些文件的HTTP响应头加入 Expires和Cache-Control参数,并指定缓存时间,这样一定时间内浏览器就不会给服务器发出任何的HTTP请求(除了强制刷新),即使在 这段时间内服务器的js或css或图片文件已经更新多次,但浏览器的数据依然是原来最能初cache的旧数据,有没有办法让浏览器拿到已经修改后的最新数 据呢?
有,方法是用ajax请求服务器最新文件,并加上请求头If-Modified-Since和Cache-Control,如下:
$.ajax({
type: "GET",
url: "static/cache.js",
dataType: "text",
beforeSend :function(xmlHttp){
xmlHttp.setRequestHeader("If-Modified-Since","0");
xmlHttp.setRequestHeader("Cache-Control","no-cache");
}
});
这里用了jquery.
这样浏览器就会把最新的文件替换掉本地旧文件。
当然,这里还一个问题就是js必须知道服务器更新了那个js、css、图片,利用cookie和时间版本应该可以解决.
jquery自从1.2开始就有ifModified和cache参数了,不用自己加header
ifModified Boolean Default: false
Allow the request to be successful only if the response has changed since the last request. This is done by checking the Last-Modified header. Default value is false, ignoring the header.
cache Boolean Default: true
Added in jQuery 1.2, if set to false it will force the pages that you request to not be cached by the browser.
$.ajax({
type: "GET",
url: "static/cache.js",
dataType: "text",
cache:false,
ifModified :true
});
有,方法是用ajax请求服务器最新文件,并加上请求头If-Modified-Since和Cache-Control,如下:
$.ajax({
type: "GET",
url: "static/cache.js",
dataType: "text",
beforeSend :function(xmlHttp){
xmlHttp.setRequestHeader("If-Modified-Since","0");
xmlHttp.setRequestHeader("Cache-Control","no-cache");
}
});
这里用了jquery.
这样浏览器就会把最新的文件替换掉本地旧文件。
当然,这里还一个问题就是js必须知道服务器更新了那个js、css、图片,利用cookie和时间版本应该可以解决.
jquery自从1.2开始就有ifModified和cache参数了,不用自己加header
ifModified Boolean Default: false
Allow the request to be successful only if the response has changed since the last request. This is done by checking the Last-Modified header. Default value is false, ignoring the header.
cache Boolean Default: true
Added in jQuery 1.2, if set to false it will force the pages that you request to not be cached by the browser.
$.ajax({
type: "GET",
url: "static/cache.js",
dataType: "text",
cache:false,
ifModified :true
});
#8
建立数据缓存,可以用Cache对象,用法和Session差不多。
#9
你这是清除客户端缓存