mirror of
https://github.com/urbit/shrub.git
synced 2025-01-06 21:18:42 +03:00
eyre: add cache
This commit is contained in:
parent
a037acd8db
commit
e0ff3b4d5f
@ -1354,6 +1354,11 @@
|
|||||||
:: ::::
|
:: ::::
|
||||||
++ eyre ^?
|
++ eyre ^?
|
||||||
|%
|
|%
|
||||||
|
+$ cache-entry
|
||||||
|
$: auth=?
|
||||||
|
$= body
|
||||||
|
$% [%payload =simple-payload:http]
|
||||||
|
== ==
|
||||||
+$ gift
|
+$ gift
|
||||||
$% :: set-config: configures the external http server
|
$% :: set-config: configures the external http server
|
||||||
::
|
::
|
||||||
@ -1373,6 +1378,9 @@
|
|||||||
:: not allowed.
|
:: not allowed.
|
||||||
::
|
::
|
||||||
[%bound accepted=? =binding]
|
[%bound accepted=? =binding]
|
||||||
|
:: notification that a cache entry has changed
|
||||||
|
::
|
||||||
|
[%grow =path]
|
||||||
==
|
==
|
||||||
::
|
::
|
||||||
+$ task
|
+$ task
|
||||||
@ -1428,6 +1436,9 @@
|
|||||||
:: %spew: set verbosity toggle
|
:: %spew: set verbosity toggle
|
||||||
::
|
::
|
||||||
[%spew veb=@]
|
[%spew veb=@]
|
||||||
|
:: remember (or update) a cache mapping
|
||||||
|
::
|
||||||
|
[%set-response url=@t entry=(unit cache-entry)]
|
||||||
==
|
==
|
||||||
:: +origin: request origin as specified in an Origin header
|
:: +origin: request origin as specified in an Origin header
|
||||||
::
|
::
|
||||||
|
@ -68,7 +68,7 @@
|
|||||||
::
|
::
|
||||||
|%
|
|%
|
||||||
+$ axle
|
+$ axle
|
||||||
$: %~2023.2.17
|
$: %~2023.3.16
|
||||||
=server-state
|
=server-state
|
||||||
==
|
==
|
||||||
:: +server-state: state relating to open inbound HTTP connections
|
:: +server-state: state relating to open inbound HTTP connections
|
||||||
@ -84,6 +84,9 @@
|
|||||||
:: the :binding into a (map (unit @t) (trie knot =action)).
|
:: the :binding into a (map (unit @t) (trie knot =action)).
|
||||||
::
|
::
|
||||||
bindings=(list [=binding =duct =action])
|
bindings=(list [=binding =duct =action])
|
||||||
|
:: cache: mapping from url to versioned entry
|
||||||
|
::
|
||||||
|
cache=(map url=@t [aeon=@ud val=(unit cache-entry)])
|
||||||
:: cors-registry: state used and managed by the +cors core
|
:: cors-registry: state used and managed by the +cors core
|
||||||
::
|
::
|
||||||
=cors-registry
|
=cors-registry
|
||||||
@ -672,6 +675,11 @@
|
|||||||
=- (fall - '*')
|
=- (fall - '*')
|
||||||
(get-header:http 'access-control-request-headers' headers)
|
(get-header:http 'access-control-request-headers' headers)
|
||||||
==
|
==
|
||||||
|
:: handle requests to the cache
|
||||||
|
::
|
||||||
|
=/ entry (~(get by cache.state) url.request)
|
||||||
|
?: &(?=(^ entry) ?=(%'GET' method.request))
|
||||||
|
(handle-cache-req authenticated request val.u.entry)
|
||||||
::
|
::
|
||||||
?- -.action
|
?- -.action
|
||||||
%gen
|
%gen
|
||||||
@ -771,6 +779,32 @@
|
|||||||
%^ return-static-data-on-duct status 'text/html'
|
%^ return-static-data-on-duct status 'text/html'
|
||||||
(error-page status authenticated url.request tape)
|
(error-page status authenticated url.request tape)
|
||||||
--
|
--
|
||||||
|
:: +handle-cache-req: respond with cached value, 404 or 500
|
||||||
|
::
|
||||||
|
++ handle-cache-req
|
||||||
|
|= [authenticated=? =request:http entry=(unit cache-entry)]
|
||||||
|
|^ ^- (quip move server-state)
|
||||||
|
?~ entry
|
||||||
|
(error-response 404 "cache entry for that binding was deleted")
|
||||||
|
?: &(auth.u.entry !authenticated)
|
||||||
|
(error-response 403 ~)
|
||||||
|
=* body body.u.entry
|
||||||
|
?- -.body
|
||||||
|
%payload
|
||||||
|
%- handle-response
|
||||||
|
:* %start
|
||||||
|
response-header.simple-payload.body
|
||||||
|
data.simple-payload.body
|
||||||
|
complete=%.y
|
||||||
|
==
|
||||||
|
==
|
||||||
|
::
|
||||||
|
++ error-response
|
||||||
|
|= [status=@ud =tape]
|
||||||
|
^- (quip move server-state)
|
||||||
|
%^ return-static-data-on-duct status 'text/html'
|
||||||
|
(error-page status authenticated url.request tape)
|
||||||
|
--
|
||||||
:: +handle-scry: respond with scry result, 404 or 500
|
:: +handle-scry: respond with scry result, 404 or 500
|
||||||
::
|
::
|
||||||
++ handle-scry
|
++ handle-scry
|
||||||
@ -2032,6 +2066,15 @@
|
|||||||
%leave ~
|
%leave ~
|
||||||
==
|
==
|
||||||
--
|
--
|
||||||
|
:: +set-response: remember (or update) a cache mapping
|
||||||
|
::
|
||||||
|
++ set-response
|
||||||
|
|= [url=@t entry=(unit cache-entry)]
|
||||||
|
^- [(list move) server-state]
|
||||||
|
=/ aeon ?^(prev=(~(get by cache.state) url) +(aeon.u.prev) 1)
|
||||||
|
=. cache.state (~(put by cache.state) url [aeon entry])
|
||||||
|
:_ state
|
||||||
|
[outgoing-duct.state %give %grow /cache/(scot %ud aeon)/(scot %t url)]~
|
||||||
:: +add-binding: conditionally add a pairing between binding and action
|
:: +add-binding: conditionally add a pairing between binding and action
|
||||||
::
|
::
|
||||||
:: Adds =binding =action if there is no conflicting bindings.
|
:: Adds =binding =action if there is no conflicting bindings.
|
||||||
@ -2318,6 +2361,12 @@
|
|||||||
:: save duct for future %give to unix
|
:: save duct for future %give to unix
|
||||||
::
|
::
|
||||||
=. outgoing-duct.server-state.ax duct
|
=. outgoing-duct.server-state.ax duct
|
||||||
|
:: send all cache mappings to runtime
|
||||||
|
::
|
||||||
|
=/ cache-moves=(list move)
|
||||||
|
%+ turn ~(tap by cache.server-state.ax)
|
||||||
|
|= [url=@t cache-val=[aeon=@ud val=(unit cache-entry)]]
|
||||||
|
[duct %give %grow /cache/(scot %u aeon.cache-val)/(scot %t url)]
|
||||||
::
|
::
|
||||||
:_ http-server-gate
|
:_ http-server-gate
|
||||||
:* :: hand back default configuration for now
|
:* :: hand back default configuration for now
|
||||||
@ -2328,7 +2377,7 @@
|
|||||||
=< give-session-tokens
|
=< give-session-tokens
|
||||||
(per-server-event [eny duct now rof] server-state.ax)
|
(per-server-event [eny duct now rof] server-state.ax)
|
||||||
::
|
::
|
||||||
closed-connections
|
(zing ~[closed-connections cache-moves])
|
||||||
==
|
==
|
||||||
::
|
::
|
||||||
?: ?=(%code-changed -.task)
|
?: ?=(%code-changed -.task)
|
||||||
@ -2447,6 +2496,10 @@
|
|||||||
%spew
|
%spew
|
||||||
=. verb.server-state.ax veb.task
|
=. verb.server-state.ax veb.task
|
||||||
`http-server-gate
|
`http-server-gate
|
||||||
|
::
|
||||||
|
%set-response
|
||||||
|
=^ moves server-state.ax (set-response:server +.task)
|
||||||
|
[moves http-server-gate]
|
||||||
==
|
==
|
||||||
::
|
::
|
||||||
++ take
|
++ take
|
||||||
@ -2638,7 +2691,8 @@
|
|||||||
+$ axle-any
|
+$ axle-any
|
||||||
$% [%~2020.10.18 =server-state-0]
|
$% [%~2020.10.18 =server-state-0]
|
||||||
[%~2022.7.26 =server-state-0]
|
[%~2022.7.26 =server-state-0]
|
||||||
[%~2023.2.17 =server-state]
|
[%~2023.2.17 =server-state-1]
|
||||||
|
[%~2023.3.16 =server-state]
|
||||||
==
|
==
|
||||||
+$ server-state-0
|
+$ server-state-0
|
||||||
$: bindings=(list [=binding =duct =action])
|
$: bindings=(list [=binding =duct =action])
|
||||||
@ -2651,6 +2705,18 @@
|
|||||||
ports=[insecure=@ud secure=(unit @ud)]
|
ports=[insecure=@ud secure=(unit @ud)]
|
||||||
outgoing-duct=duct
|
outgoing-duct=duct
|
||||||
==
|
==
|
||||||
|
+$ server-state-1
|
||||||
|
$: bindings=(list [=binding =duct =action])
|
||||||
|
=cors-registry
|
||||||
|
connections=(map duct outstanding-connection)
|
||||||
|
=authentication-state
|
||||||
|
=channel-state
|
||||||
|
domains=(set turf)
|
||||||
|
=http-config
|
||||||
|
ports=[insecure=@ud secure=(unit @ud)]
|
||||||
|
outgoing-duct=duct
|
||||||
|
verb=@
|
||||||
|
==
|
||||||
--
|
--
|
||||||
|= old=axle-any
|
|= old=axle-any
|
||||||
^+ ..^$
|
^+ ..^$
|
||||||
@ -2659,8 +2725,9 @@
|
|||||||
=, server-state-0.old
|
=, server-state-0.old
|
||||||
%= ..^$
|
%= ..^$
|
||||||
ax ^- axle
|
ax ^- axle
|
||||||
:* %~2023.2.17
|
:* %~2023.3.16
|
||||||
(insert-binding [[~ /~/name] outgoing-duct [%name ~]] bindings)
|
(insert-binding [[~ /~/name] outgoing-duct [%name ~]] bindings)
|
||||||
|
*(map url=@t [aeon=@ud val=(unit cache-entry)])
|
||||||
cors-registry
|
cors-registry
|
||||||
connections
|
connections
|
||||||
authentication-state
|
authentication-state
|
||||||
@ -2676,8 +2743,9 @@
|
|||||||
=, server-state-0.old
|
=, server-state-0.old
|
||||||
%= ..^$
|
%= ..^$
|
||||||
ax ^- axle
|
ax ^- axle
|
||||||
:* %~2023.2.17
|
:* %~2023.3.16
|
||||||
bindings
|
bindings
|
||||||
|
*(map url=@t [aeon=@ud val=(unit cache-entry)])
|
||||||
cors-registry
|
cors-registry
|
||||||
connections
|
connections
|
||||||
authentication-state
|
authentication-state
|
||||||
@ -2690,6 +2758,24 @@
|
|||||||
== ==
|
== ==
|
||||||
::
|
::
|
||||||
%~2023.2.17
|
%~2023.2.17
|
||||||
|
=, server-state-1.old
|
||||||
|
%= ..^$
|
||||||
|
ax ^- axle
|
||||||
|
:* %~2023.3.16
|
||||||
|
bindings
|
||||||
|
*(map url=@t [aeon=@ud val=(unit cache-entry)])
|
||||||
|
cors-registry
|
||||||
|
connections
|
||||||
|
authentication-state
|
||||||
|
channel-state
|
||||||
|
domains
|
||||||
|
http-config
|
||||||
|
ports
|
||||||
|
outgoing-duct
|
||||||
|
verb
|
||||||
|
== ==
|
||||||
|
::
|
||||||
|
%~2023.3.16
|
||||||
:: enable https redirects if certificate configured
|
:: enable https redirects if certificate configured
|
||||||
::
|
::
|
||||||
=. redirect.http-config.server-state.old
|
=. redirect.http-config.server-state.old
|
||||||
@ -2757,6 +2843,14 @@
|
|||||||
%- =< request-is-logged-in:authentication
|
%- =< request-is-logged-in:authentication
|
||||||
(per-server-event [eny *duct now rof] server-state.ax)
|
(per-server-event [eny *duct now rof] server-state.ax)
|
||||||
%*(. *request:http header-list ['cookie' u.cookies]~)
|
%*(. *request:http header-list ['cookie' u.cookies]~)
|
||||||
|
::
|
||||||
|
[%cache @ @ ~]
|
||||||
|
?~ aeon=(slaw %ud i.t.tyl) [~ ~]
|
||||||
|
?~ url=(slaw %t i.t.t.tyl) [~ ~]
|
||||||
|
?~ entry=(~(get by cache) u.url) [~ ~]
|
||||||
|
?. =(u.aeon aeon.u.entry) [~ ~]
|
||||||
|
?~ val=val.u.entry [~ ~]
|
||||||
|
``noun+!>(u.val)
|
||||||
==
|
==
|
||||||
?. ?=(%$ ren)
|
?. ?=(%$ ren)
|
||||||
[~ ~]
|
[~ ~]
|
||||||
|
Loading…
Reference in New Issue
Block a user