ذاكرة التخزين المؤقت بثقة
فائقة فائقة وتيقة ( حوالي 1.28 كيلو بايت Gzibed )
يعمل في أي وقت تشغيل JavaScript (عقدة أو متصفح)
npm install pure-cacheyarn add pure-cache < script src =" https://unpkg.com/pure-cache/dist/pure-cache.umd.js " > </ script > مكتبة الاستيراد
import PureCache from 'pure-cache' ;
// or const PureCache = require('pure-cache');إنشاء مثيل Cachestore
// Create instance of cache store and set cache expiry timeout to 500ms
const cacheStore = new PureCache ( { expiryCheckInterval : 500 } ) ;الإعداد معالج انتهاء الصلاحية
// Setup a expiry listener, this will be called when data expires
const onExpiry = ( { key , data : { value , expiryAt } } ) => {
// Do something with expired key
console . log ( `Key: ${ key } with value: ${ value } expired at ${ expiryAt } .` ) ;
} ;
cacheStore . on ( 'expiry' , onExpiry ) ;ضع/الحصول على بيانات من Cachestore
// Put 'bar' data into 'foo' key in cache and configure it to expire after 30s
cacheStore . put ( 'foo' , 'bar' , 30000 ) ;
// Get 'foo' key value from cache
cacheStore . get ( 'foo' ) ; // { value: 'bar', addedAt: 1527052395294, expiryAt: 1527052425294 }انتظر انتهاء الصلاحية
// Wait till expiry time(basically 30+ seconds in this case)
const wait = t => new Promise ( r => setTimeout ( r , t ) ) ;
await wait ( 31000 ) ;
// Now the cache will return null value for 'foo' key
cacheStore . get ( 'foo' ) ; // nullمستمعي التنظيف
// remove listeners after you are done
cacheStore . off ( 'expiry' , onExpiry ) ;
// IMPORTANT! When done, make sure you cleanup the instance
cacheStore . dispose ( ) ;الخروج API للاستخدام المتقدم.
يتم تشغيل الأحداث عند إجراء عمليات مثل ADD أو GET أو إزالة أو واضحة على Cachestore أو عندما تنتهي صلاحية ذاكرة التخزين المؤقت.
انتهاء الصلاحية
cacheStore . on ( 'expiry' , ( { key , data : { value , addedAt , expiryAt } } ) => {
// ...
} ) ;يضيف
cacheStore . on ( 'add' , ( { key , data : { value , addedAt , expiryAt } } ) => {
// ...
} ) ;يحصل
cacheStore . on ( 'get' , ( { key , data : { value , addedAt , expiryAt } } ) => {
// ...
} ) ;يزيل
cacheStore . on ( 'remove' , ( { key , data : { value , addedAt , expiryAt } } ) => {
// ...
} ) ;واضح
cacheStore . on ( 'clear' , ( ) => {
// ...
} ) ; شكرًا على قضاء بعض الوقت للمساهمة ، يرجى قراءة المستندات والخروج من SRC لفهم كيفية عمل الأشياء.
وجدت مشكلة؟ تريد ميزة جديدة؟ بادئ ذي بدء ، تعرف على ما إذا كانت مشكلتك أو فكرتك قد تم الإبلاغ عنها بالفعل. إذا لم تفعل ، فقط افتح مشكلة واضحة وصفية جديدة.
طلبات السحب هي أعظم المساهمات ، لذا تأكد من تركيزها في النطاق ، وتجنب الالتزامات غير ذات الصلة.
git clone https://github.com/<your-username>/pure-cachecd pure-cachegit checkout -b my-new-featureyarngit commit -am 'Add some feature'git push origin my-new-featureترخيص معهد ماساتشوستس للتكنولوجيا © Ganapati VS