当前位置: 首页 > 工具软件 > Webmachine > 使用案例 >

用webmachine 的缓存 是如此简单

齐鸿光
2023-12-01

HTTP Caching Support

HTTP caching support is also quite easy, with functions allowing resources to define (e.g.) last_modifiedexpires, and generate_etag. For instance, since representations of this resource vary only by URI Path, I could use an extremely simple entity tag unfit for most real applications but sufficient for this example:

generate_etag(ReqData, Context) -> {wrq:raw_path(ReqData), ReqData, Context}.

Similarly, here's a trivial expires rule:

expires(ReqData, Context) -> {{{2021,1,1},{0,0,0}}, ReqData, Context}.

And now the response from our earlier request is appropriately tagged:

HTTP/1.1 200 OK
Vary: Accept
Server: MochiWeb/1.1 WebMachine/0.97
Expires: Fri, 01 Jan 2021 00:00:00 GMT
ETag: /demo/authdemo
Date: Sun, 15 Mar 2009 02:59:02 GMT
Content-Type: text/html
Content-Length: 59

<html><body>Hello authdemo from Webmachine.
</body></html>
 类似资料: