Add the STORE callback method

So activity-servist can ask the server to cache
objects.
This commit is contained in:
Jaidyn Ann 2024-12-20 17:24:17 -06:00
parent a37fc2bbfe
commit fe188a8aa7
2 changed files with 18 additions and 10 deletions

View File

@ -76,6 +76,12 @@ inbox, and decide what to do with it!"
(setq *inbox* (append *inbox* (list obj))))
(defmethod as:store ((obj json-ld:object))
"activity-servist callback: Store a foreign JSON-LD OBJECT (fetched during
operation of the server) in our object-store."
(setf (gethash (json-ld:@id obj) *store*) obj))
;;; ID-management
;;; ————————————————————————————————————————
@ -115,14 +121,6 @@ Otherwise, assume “https”."
(format nil "https://~A" hostname))))
;;; Data-management
;;; ————————————————————————————————————————
(defun save (obj)
"Save an object to our object-store, *STORE*."
(setf (gethash (json-ld:@id obj) *store*) obj))
;;; Users
;;; ————————————————————————————————————————

View File

@ -22,11 +22,12 @@
;; Functions
:server :start-server
;; Methods
:receive
:receive :store
;; Globals
*config*))
(in-package #:activity-servist)
(defvar *last* nil)
;;; Globals
@ -98,9 +99,18 @@ Actors, and then calls RECEIVE on them in turn."))
(let* ((actor-uri (ignore-errors (activity-vocabulary:actor obj))))
(when actor-uri
(or (retrieve actor-uri)
(fetch-and-receive actor-uri)))))
(fetch-and-store actor-uri)))))
(defgeneric store (obj)
(:documentation
"Stores an object in a object-store accessible with the callback function
RETRIEVE, likely for caching purposes.
You should overload this generic with a method accepting JSON-LD:OBJECTs, as it
is necessary for activity-servist to function. When called by activity-servist,
this is solely used to store fetched foreign objects."))
;;; Fetching foreign objects