Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@luvio/service-cache

Package Overview
Dependencies
Maintainers
0
Versions
25
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.8.0 to 5.9.0

dist/types/v1/default.d.ts

44

dist/types/v1/cache.d.ts

@@ -1,4 +0,2 @@

import { type KeySet } from '@luvio/service-store/v1';
import type { Key, NamedStoreService } from '@luvio/service-store/v1';
import type { TypeStoreEntry } from './type-store';
import { type Key, type KeySet } from './keys';
/**

@@ -27,4 +25,7 @@ * The "canonical" cache control metadata. Typically set by

*/
export type CacheEntry<T> = TypeStoreEntry<T> & {
cacheControlMetadata: CacheControlMetadata;
export type CacheEntry<T> = {
value: T;
metadata: {
cacheControl: CacheControlMetadata;
};
};

@@ -41,29 +42,8 @@ /**

toKeySet(keys: Key[]): KeySet;
record(): RecordableCache;
};
export declare class DefaultCache implements Cache {
protected services: NamedStoreService;
constructor(services: NamedStoreService);
/**
* Returns the cache entry at the specified key; undefined if no
* such entry exists.
*
* @param key store key
*/
get<T>(key: Key): CacheEntry<T> | undefined;
/**
* Adds the specified key/value to the cache.
*
* @param key key at which to store value
* @param entry value to be stored
*/
set<T>(key: Key, entry: CacheEntry<T>): void;
/**
* Removes the cache entry associated with the specified key.
*
* @param key key to be removed from the store
*/
delete(key: Key): void;
length(): number;
keys(): KeySet;
toKeySet(keys: Key[]): KeySet;
}
export type RecordableCache = Cache & {
keysRead: KeySet;
missingKeysRead: KeySet;
keysUpdated: KeySet;
};
import { type Cache } from './cache';
import type { NamedService, ServiceDescriptor } from '@luvio/utils';
import type { StoreService } from '@luvio/service-store/v1';
export { RecordableCache } from './recordable-cache';
export { TypeStore, TypeStoreEntry } from './type-store';
export { Cache, CacheControlMetadata, CacheEntry } from './cache';
export type NamedCacheService<Name extends string = 'cache'> = NamedService<Name, Cache>;
export type CacheServiceDescriptor = ServiceDescriptor<Cache, 'cache', '1.0'>;
export declare function buildServiceDescriptor(store: StoreService): CacheServiceDescriptor;
export declare function buildServiceDescriptor(): CacheServiceDescriptor;

@@ -1,7 +0,7 @@

import { type Key, type KeySet, KeySetImpl } from '@luvio/service-store/v1';
import type { CacheEntry, Cache } from './cache';
import { type Key, type KeySet, KeySetImpl } from './keys';
import type { CacheEntry, Cache, RecordableCache } from './cache';
/**
A utility class for recording actions made on a cache.
*/
export declare class RecordableCache implements Cache {
export declare class DefaultRecordableCache implements Cache {
protected baseCache: Cache;

@@ -18,2 +18,3 @@ constructor(baseCache: Cache);

toKeySet(keys: Key[]): KeySet;
record(): RecordableCache;
}

@@ -7,45 +7,56 @@ /**

import { KeySetImpl } from '@luvio/service-store/v1';
class DefaultCache {
constructor(services) {
this.services = services;
/**
* A collection of keys, in no particular order.
*/
class KeySetImpl {
constructor(initialKeys) {
// TODO - probably better to use Set<Key>
this.data = {};
this.lengthInternal = 0;
if (initialKeys) {
initialKeys.forEach((key) => {
this.add(key);
});
}
}
/**
* Returns the cache entry at the specified key; undefined if no
* such entry exists.
*
* @param key store key
*/
get(key) {
return this.services.store.get(key);
add(key) {
this.data[key] = true;
// TODO - need to account for adding a key that was already in the set
this.lengthInternal++;
}
/**
* Adds the specified key/value to the cache.
*
* @param key key at which to store value
* @param entry value to be stored
*/
set(key, entry) {
if (entry.cacheControlMetadata.type === 'no-store') {
return;
contains(key) {
return this.data[key] === true;
}
elements() {
return Object.keys(this.data);
}
get length() {
return this.lengthInternal;
}
overlaps(other) {
const otherKeys = other.elements();
for (let j = 0; j < otherKeys.length; ++j) {
if (this.contains(otherKeys[j])) {
return true;
}
}
return this.services.store.set(key, entry);
return false;
}
/**
* Removes the cache entry associated with the specified key.
*
* @param key key to be removed from the store
*/
delete(key) {
this.services.store.delete(key);
difference(other) {
const value = new KeySetImpl();
this.elements().forEach((key) => {
if (!other.contains(key)) {
value.add(key);
}
});
return value;
}
length() {
return this.services.store.length();
isSubsetOf(other) {
return this.difference(other).length === 0;
}
keys() {
return this.services.store.keys();
equals(other) {
return this.length === other.length && this.elements().every((key) => other.contains(key));
}
toKeySet(keys) {
return this.services.store.toKeySet(keys);
toString() {
return `<<${JSON.stringify(this.elements())}>>`;
}

@@ -57,3 +68,3 @@ }

*/
class RecordableCache {
class DefaultRecordableCache {
constructor(baseCache) {

@@ -90,12 +101,62 @@ this.baseCache = baseCache;

}
record() {
return this.baseCache.record();
}
}
function buildServiceDescriptor(store) {
class DefaultCache {
constructor() {
this.data = {};
}
/**
* Returns the cache entry at the specified key; undefined if no
* such entry exists.
*
* @param key store key
*/
get(key) {
return this.data[key];
}
/**
* Adds the specified key/value to the cache.
*
* @param key key at which to store value
* @param entry value to be stored
*/
set(key, entry) {
if (entry.metadata.cacheControl.type === 'no-store') {
return;
}
this.data[key] = entry;
}
/**
* Removes the cache entry associated with the specified key.
*
* @param key key to be removed from the store
*/
delete(key) {
delete this.data[key];
}
length() {
return this.keys().length;
}
keys() {
return new KeySetImpl(Object.keys(this.data));
}
toKeySet(keys) {
return new KeySetImpl(keys);
}
record() {
return new DefaultRecordableCache(this);
}
}
function buildServiceDescriptor() {
return {
type: 'cache',
version: '1.0',
service: new DefaultCache({ store }),
service: new DefaultCache(),
};
}
export { RecordableCache, buildServiceDescriptor };
export { buildServiceDescriptor };

@@ -1,4 +0,2 @@

import { type KeySet } from '@luvio/service-store/v1';
import type { Key, NamedStoreService } from '@luvio/service-store/v1';
import type { TypeStoreEntry } from './type-store';
import { type Key, type KeySet } from './keys';
/**

@@ -27,4 +25,7 @@ * The "canonical" cache control metadata. Typically set by

*/
export type CacheEntry<T> = TypeStoreEntry<T> & {
cacheControlMetadata: CacheControlMetadata;
export type CacheEntry<T> = {
value: T;
metadata: {
cacheControl: CacheControlMetadata;
};
};

@@ -41,29 +42,8 @@ /**

toKeySet(keys: Key[]): KeySet;
record(): RecordableCache;
};
export declare class DefaultCache implements Cache {
protected services: NamedStoreService;
constructor(services: NamedStoreService);
/**
* Returns the cache entry at the specified key; undefined if no
* such entry exists.
*
* @param key store key
*/
get<T>(key: Key): CacheEntry<T> | undefined;
/**
* Adds the specified key/value to the cache.
*
* @param key key at which to store value
* @param entry value to be stored
*/
set<T>(key: Key, entry: CacheEntry<T>): void;
/**
* Removes the cache entry associated with the specified key.
*
* @param key key to be removed from the store
*/
delete(key: Key): void;
length(): number;
keys(): KeySet;
toKeySet(keys: Key[]): KeySet;
}
export type RecordableCache = Cache & {
keysRead: KeySet;
missingKeysRead: KeySet;
keysUpdated: KeySet;
};
import { type Cache } from './cache';
import type { NamedService, ServiceDescriptor } from '@luvio/utils';
import type { StoreService } from '@luvio/service-store/v1';
export { RecordableCache } from './recordable-cache';
export { TypeStore, TypeStoreEntry } from './type-store';
export { Cache, CacheControlMetadata, CacheEntry } from './cache';
export type NamedCacheService<Name extends string = 'cache'> = NamedService<Name, Cache>;
export type CacheServiceDescriptor = ServiceDescriptor<Cache, 'cache', '1.0'>;
export declare function buildServiceDescriptor(store: StoreService): CacheServiceDescriptor;
export declare function buildServiceDescriptor(): CacheServiceDescriptor;

@@ -1,7 +0,7 @@

import { type Key, type KeySet, KeySetImpl } from '@luvio/service-store/v1';
import type { CacheEntry, Cache } from './cache';
import { type Key, type KeySet, KeySetImpl } from './keys';
import type { CacheEntry, Cache, RecordableCache } from './cache';
/**
A utility class for recording actions made on a cache.
*/
export declare class RecordableCache implements Cache {
export declare class DefaultRecordableCache implements Cache {
protected baseCache: Cache;

@@ -18,2 +18,3 @@ constructor(baseCache: Cache);

toKeySet(keys: Key[]): KeySet;
record(): RecordableCache;
}
{
"name": "@luvio/service-cache",
"version": "5.8.0",
"version": "5.9.0",
"private": false,

@@ -34,5 +34,7 @@ "description": "OneStore Cache Service definition",

"dependencies": {
"@luvio/service-store": "^5.8.0",
"@luvio/utils": "^5.8.0"
"@luvio/utils": "^5.9.0"
},
"volta": {
"extends": "../../../../package.json"
},
"bundlesize": [

@@ -39,0 +41,0 @@ {

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