แคชด้วยความมั่นใจ
เป็น Ultra Fast & Tiny ( ประมาณ 1.28KB GZIPPED
ทำงานในรันไทม์ JavaScript (Node หรือ Browser)
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 ( ) ;Checkout API สำหรับการใช้งานขั้นสูง
เหตุการณ์จะถูกทริกเกอร์เมื่อการดำเนินการเช่นเพิ่มรับลบออกจะดำเนินการบน 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ใบอนุญาต MIT © Ganapati vs