discourse/app/assets/javascripts/pretty-text/oneboxer-cache.js.es6
Mark VanLandingham 11f50eee3b
DEV: Remove pretty_text import hack & still work server-side ()
* FIX: move attachment_css_class constant out of upload-short-url for discourse-markdown-it

* Use setTimeout instead of ember later

* WIP. Not sure if this worked.

* oneboxer cache in separate file

* Reset onebox cache still

* set functions for oneboxers cache
2019-10-31 11:54:46 -05:00

30 lines
618 B
JavaScript

export let localCache = {};
export let failedCache = {};
// Sometimes jQuery will return URLs with trailing slashes when the
// `href` didn't have them.
export function resetLocalCache() {
localCache = {};
}
export function resetFailedCache() {
failedCache = {};
}
export function setLocalCache(key, value) {
localCache[key] = value;
}
export function setFailedCache(key, value) {
failedCache[key] = value;
}
export function normalize(url) {
return url.replace(/\/$/, "");
}
export function lookupCache(url) {
const cached = localCache[normalize(url)];
return cached && cached.prop("outerHTML");
}