Skip to content

Commit

Permalink
Improve TS definitions, kriszyp#2
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Oct 18, 2021
1 parent 4177239 commit 4b67272
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ myValue.getValue('key') -> return the object above as long as it is still cached

The `WeakLRUCache` class extends the native `Map` class and also includes the following methods, which are the primary intended interactions with the cache:

### getValue(key, expirationPriority?)
### getValue(key)
Gets the value referenced by the given key and returns it. If the value is no longer cached, will return undefined.

### setValue(key, value, expirationPriority?)
Expand Down
21 changes: 18 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,24 @@ interface WeakLRUCacheOptions {
deferRegister?: boolean;
}

export class WeakLRUCache<K, V> extends Map<K, V> {
export class CacheEntry<V> {
value?: V
deref?(): V
}

export class WeakLRUCache<K, V> extends Map<K, CacheEntry<V>> {
constructor(options?: WeakLRUCacheOptions);

getValue(key: K, expirationPriority?: number): V | undefined;
setValue(key: K, value: V, expirationPriority?: number): void;
/**
* Get a value from the cache, if it is still in memory. If the value is no longer cached, will return undefined.
* @param key The key to use to retrieve the value
*/
getValue(key: K): V | undefined;
/**
* Put a key-value into the cache
* @param key The key to use to insert the entry
* @param value The value to insert into the cache
* @param expirationPriority A priority for expiration, a higher value will expire sooner
*/
setValue(key: K, value: V, expirationPriority?: number): void;
}

0 comments on commit 4b67272

Please sign in to comment.