@luvio/service-cache
Advanced tools
Comparing version 5.8.0 to 5.9.0
@@ -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 @@ { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18703
1
15
427
10
18
1
- Removed@luvio/service-store@^5.8.0
- Removed@aml-org/amf-antlr-parsers@0.6.22(transitive)
- Removed@luvio/generator-ts@5.23.0(transitive)
- Removed@luvio/jsonschema-validate@5.23.0(transitive)
- Removed@luvio/jwt-manager@5.23.0(transitive)
- Removed@luvio/model@5.23.0(transitive)
- Removed@luvio/service-aura-network@5.23.0(transitive)
- Removed@luvio/service-fetch-network@5.23.0(transitive)
- Removed@luvio/service-provisioner@5.23.0(transitive)
- Removed@luvio/service-store@5.23.0(transitive)
- Removedajv@6.12.6(transitive)
- Removedamf-client-js@5.2.6(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjwt-decode@3.1.2(transitive)
- Removedprettier@2.8.8(transitive)
- Removedpunycode@2.3.1(transitive)
- Removeduri-js@4.4.1(transitive)
Updated@luvio/utils@^5.9.0