New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@luvio/service-cache

Package Overview
Dependencies
Maintainers
0
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@luvio/service-cache - npm Package Compare versions

Comparing version 5.25.0 to 5.26.0

dist/types/v1/__tests__/filtered-cache.spec.d.ts

3

dist/types/v1/cache.d.ts

@@ -48,2 +48,3 @@ import { type Key, type KeySet } from './keys';

record(): RecordableCache;
filter(predicate: FilterPredicate): FilteredCache;
};

@@ -55,1 +56,3 @@ export type RecordableCache = Cache & {

};
export type FilteredCache = Cache;
export type FilterPredicate = (key: Key, value: CacheEntry<unknown>) => boolean;

3

dist/types/v1/default.d.ts

@@ -1,3 +0,3 @@

import { type CacheEntry, type Cache, type RecordableCache } from './cache';
import { type Key, type KeySet } from './keys';
import type { CacheEntry, Cache, FilteredCache, RecordableCache, FilterPredicate } from './cache';
export declare class DefaultCache implements Cache {

@@ -30,2 +30,3 @@ constructor();

record(): RecordableCache;
filter(predicate: FilterPredicate): FilteredCache;
}

@@ -100,5 +100,58 @@ /**

record() {
return this.baseCache.record();
return new DefaultRecordableCache(this);
}
filter(predicate) {
return new DefaultFilteredCache(this, predicate);
}
}
/**
A utility class for filtering cache entries based on a given predicate.
*/
class DefaultFilteredCache {
constructor(baseCache, predicate) {
this.baseCache = baseCache;
this.predicate = predicate;
}
delete(key) {
this.baseCache.delete(key);
}
get(key) {
const result = this.baseCache.get(key);
// if we're chaining filtered caches together, then it's possible the result will be undefined here
if (result && this.predicate(key, result)) {
return result;
}
return undefined;
}
set(key, value) {
this.baseCache.set(key, value);
}
length() {
return this.getFilteredKeys().length;
}
keys() {
return this.getFilteredKeys();
}
toKeySet(keys) {
return this.baseCache.toKeySet(keys);
}
record() {
return new DefaultRecordableCache(this);
}
filter(predicate) {
return new DefaultFilteredCache(this, predicate);
}
getFilteredKeys() {
const filteredKeySet = new KeySetImpl();
this.baseCache
.keys()
.elements()
.forEach((key) => {
if (this.get(key)) {
filteredKeySet.add(key);
}
});
return filteredKeySet;
}
}

@@ -150,2 +203,5 @@ class DefaultCache {

}
filter(predicate) {
return new DefaultFilteredCache(this, predicate);
}
}

@@ -152,0 +208,0 @@

@@ -48,2 +48,3 @@ import { type Key, type KeySet } from './keys';

record(): RecordableCache;
filter(predicate: FilterPredicate): FilteredCache;
};

@@ -55,1 +56,3 @@ export type RecordableCache = Cache & {

};
export type FilteredCache = Cache;
export type FilterPredicate = (key: Key, value: CacheEntry<unknown>) => boolean;

@@ -1,3 +0,3 @@

import { type CacheEntry, type Cache, type RecordableCache } from './cache';
import { type Key, type KeySet } from './keys';
import type { CacheEntry, Cache, FilteredCache, RecordableCache, FilterPredicate } from './cache';
export declare class DefaultCache implements Cache {

@@ -30,2 +30,3 @@ constructor();

record(): RecordableCache;
filter(predicate: FilterPredicate): FilteredCache;
}
{
"name": "@luvio/service-cache",
"version": "5.25.0",
"version": "5.26.0",
"private": false,

@@ -33,3 +33,3 @@ "description": "OneStore Cache Service definition",

"dependencies": {
"@luvio/utils": "5.25.0"
"@luvio/utils": "5.26.0"
},

@@ -36,0 +36,0 @@ "volta": {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc