首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Hunchentoot提供的页面上禁用缓存?

如何在Hunchentoot提供的页面上禁用缓存?
EN

Stack Overflow用户
提问于 2021-04-26 03:40:09
回答 1查看 54关注 0票数 2

我正在尝试禁用Hunchentoot的页面缓存,以简化本地主机上的web开发。

据我所知,应该使用函数no-cache,但我不确定如何合并此函数。我目前有以下代码可以正确地评估,但是这与动态提供的内容相关,所以我无法检查no-cache函数是否正确。此外,我也不知道如何向处理程序添加处理程序函数。

代码语言:javascript
复制
(hunchentoot:define-easy-handler
  (test-fn :uri "/test.html") (name)
  (setf (hunchentoot:content-type*) "text/plain")
  (hunchentoot:no-cache)
  (format nil "Hey~@[ ~A~]!" name))

我找不到一种向静态分派和处理程序添加无缓存的方法,比如following

代码语言:javascript
复制
(push (hunchentoot:create-static-file-dispatcher-and-handler
        "/url.html" "/path/to/www_/actual-page.html")
  hunchentoot:*dispatch-table*)

上面的例子绕过了缓存,因为我相信它是动态地为页面提供服务。

下面是我的服务器配置。当前正在缓存静态页面。我想了解Hunchentoot机制,该机制不仅禁用所有资源的缓存,还禁用指定资源的缓存(为其他资源保留它)。

代码语言:javascript
复制
(defvar *ssg-web-server* (hunchentoot:start 
              (make-instance 'hunchentoot:easy-acceptor 
                     :address "127.0.0.1" 
                     :port 4242 
                     :document-root #p"/path/to/www_/"
                     :persistent-connections-p t
                     :read-timeout 3.0 
                     :write-timeout 3.0
                     :access-log-destination nil
                     :message-log-destination nil)))
EN

回答 1

Stack Overflow用户

发布于 2021-04-26 19:53:11

create-static-file-dispatcher-and-handler接受回调:

回调在发送文件之前运行,可用于设置头部或检查授权;参数是文件名和(猜测的)内容类型。

我想你可以这样写:

代码语言:javascript
复制
(defun no-cache-static-callback (file content-type)
  (declare (ignore file content-type))
  (no-cache))

您将按如下方式传递此函数,即使用NIL content-type和回调函数:

代码语言:javascript
复制
(create-static-file-dispatcher-and-handler
  "/url.html" 
  "/path/to/www_/actual-page.html" 
  nil
  #'no-cache-static-callback)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67257539

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档