pure cache
1.0.0
자신감이있는 캐시
Ultra Fast & Tiny ( 약 1.28kB Gzipped ) 근거리 실시간 캐시 만료 기능이있는 메모리 자바 스크립트 캐시
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');캐시 스토어 인스턴스를 만듭니다
// 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 ) ;캐시 스토어에서 데이터를 넣거나 가져옵니다
// 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.
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' , ( ) => {
// ...
} ) ; 시간을 내 주셔서 감사합니다.
문제를 찾았습니까? 새로운 기능을 원하십니까? 우선 귀하의 문제 나 아이디어가 이미보고되었는지 확인하십시오. 그렇지 않다면, 새로운 명확하고 설명적인 문제를여십시오.
풀 요청은 가장 큰 기여이므로 범위에 중점을두고 관련없는 커밋을 피하십시오.
git clone https://github.com/<your-username>/pure-cachecd pure-cache 로 이동하십시오git checkout -b my-new-featureyarngit commit -am 'Add some feature'git push origin my-new-featureMIT 라이센스 © Ganapati vs