2

我正在尝试禁用 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))

我无法找到将无缓存添加到静态调度和处理程序的方法,例如

(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)))
4

1 回答 1

1

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)
于 2021-04-26T11:53:11.330 回答