mirror of
https://github.com/penpot/penpot.git
synced 2025-07-27 08:47:22 +02:00
♻️ Refactor embed resouces
This commit is contained in:
parent
42072f2584
commit
6a68e9c118
15 changed files with 312 additions and 260 deletions
26
frontend/src/app/util/cache.cljs
Normal file
26
frontend/src/app/util/cache.cljs
Normal file
|
@ -0,0 +1,26 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; Copyright (c) UXBOX Labs SL
|
||||
|
||||
(ns app.util.cache
|
||||
(:require
|
||||
[app.util.time :as dt]
|
||||
[beicon.core :as rx]))
|
||||
|
||||
(defonce cache (atom {}))
|
||||
|
||||
(defn with-cache
|
||||
[{:keys [key max-age]} observable]
|
||||
(let [entry (get @cache key)
|
||||
age (when entry
|
||||
(dt/diff (dt/now)
|
||||
(:created-at entry)))]
|
||||
(if (and (some? entry) (< age max-age))
|
||||
(rx/of (:data entry))
|
||||
(->> observable
|
||||
(rx/tap
|
||||
(fn [data]
|
||||
(let [entry {:created-at (dt/now) :data data}]
|
||||
(swap! cache assoc key entry))))))))
|
Loading…
Add table
Add a link
Reference in a new issue