Sets a maximum age (minimum one day) for script storage values, after which they are deleted
This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/562172/1881822/Temporary-Script-Storage.js
या क्लासच्या उदाहरणाद्वारे सेट केलेले आणि प्रवेश केलेले स्टोरेज फक्त तुम्ही कंस्ट्रक्टरमध्ये सेट केलेल्या जीवनकाळ तितके काळ राहील, परंतु ते कमीतकमी एक दिवस असले पाहिजे. डिफॉल्ट 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 प्रदान केली पाहिजे.