Sets a maximum age (minimum one day) for script storage values, after which they are deleted
이 스크립트는 직접 설치하는 용도가 아닙니다. 다른 스크립트에서 메타 지시문 // @require https://update.greasyfork.org/scripts/562172/1881822/Temporary-Script-Storage.js을(를) 사용하여 포함하는 라이브러리입니다.
이 클래스의 인스턴스를 통해 설정되고 액세스되는 저장소는 생성자에서 설정한 수명 동안만 존재하지만, 최소한 1일 이상이어야 합니다. 기본값은 30일입니다. 그 이후 sweepExpiredEntries()가 호출될 때 만료되어 삭제되며, setInterval()로 일정을 잡을 수 있습니다.
이 라이브러리는 GM의 setValue()를 통해 직접 설정된 스크립트 저장소에 영향을 주지 않습니다. 그러한 저장소는 정상적으로 동작합니다.
사용 예시:
const persistentStorage = new TTLStorage();
await persistentStorage.ready();
setInterval(() => persistentStorage.sweepExpiredEntries(), 1000 * 60 * 60 * 24);
try {
await persistentStorage.set("key1", "hello"); // throws
const msg = persistentStorage.get("key1"); // fast memory read
await persistentStorage.delete("key1"); // throws
} catch {}
추가로, 이 라이브러리를 사용하는 모든 스크립트는 다음 메타데이터를 포함해야 합니다:
// @grant GM.getValue
// @grant GM.setValue
// @grant GM.deleteValue
// @grant GM.listValues
// @grant GM.info
각 라이브러리가 필요로 하는 것을 자체 메타데이터에 포함하는 것만으로는 충분하지 않으므로 이것이 필요합니다. 최상위 스크립트는 모든 종속성에 필요한 @requires와 @grants를 제공해야 합니다.