问题描述
我正在尝试禁用 Hunchentoot 的页面缓存,以简化本地主机上的 Web 开发。
据我所知,函数 no-cache 是要使用的,但我不确定如何合并它。我目前有以下代码可以正确评估,但是这与动态提供的内容有关,因此我无法检查 no-cache 功能是否正确。我也不知道如何向处理程序添加处理程序函数。
(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:
(push (hunchentoot:create-static-file-dispatcher-and-handler
"/url.html" "/path/to/www_/actual-page.html")
hunchentoot:*dispatch-table*)
上面的例子绕过了缓存,因为我相信它是动态地为页面提供服务。
以下是我的服务器配置。当前正在缓存静态页面。我想了解 Hunchentoot 机制来禁用所有资源的缓存,但也禁用指定的资源(为其他资源保留它)。
(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)))
解决方法
create-static-file-dispatcher-and-handler
接受回调:
CALLBACK 在发送文件之前运行,可以使用 设置标题或检查授权; 参数是文件名和(猜测的)内容类型。
我想你可以写:
(defun no-cache-static-callback (file content-type)
(declare (ignore file content-type))
(no-cache))
您将按如下方式传递此函数,即使用 NIL 内容类型和回调函数:
(create-static-file-dispatcher-and-handler
"/url.html"
"/path/to/www_/actual-page.html"
nil
#'no-cache-static-callback)