import { CustomJSONStringify as e } from "../../functions/utils/serialize.utils.mjs";
import { BaseCacheDevice as t } from "./BaseCacheDevice.mjs";
//#region libs/shared/common/src/data-structures/cacheDevices/AttachableMemoryCacheDevice.ts
var n = class extends t {
	isAttached = !1;
	get(e) {
		return this.getInMemory(e);
	}
	set(e, t) {
		this.setInMemory(e, t);
	}
	serialize() {
		return Object.fromEntries([...this.inMemoryCache].map(([t, n]) => [t, e(n)]));
	}
	attach(t) {
		if (this.isAttached) throw Error("can't reattach cache device");
		return this.isAttached = !0, (...n) => {
			let r = e(n), i = this.get(r);
			if (i !== void 0) return i;
			let a = t(...n);
			return this.set(r, a), a;
		};
	}
};
//#endregion
export { n as AttachableMemoryCacheDevice };
