@zuplo/runtime 6.55.0 → 6.55.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/esm/index.js +7 -7
- package/out/types/index.d.ts +33 -1
- package/package.json +1 -1
package/out/types/index.d.ts
CHANGED
|
@@ -4801,19 +4801,46 @@ export declare type McpToolHandler<TArgs = any> = (
|
|
|
4801
4801
|
context: ZuploContext
|
|
4802
4802
|
) => Promise<CallToolResult> | CallToolResult;
|
|
4803
4803
|
|
|
4804
|
+
declare interface MemoryCacheOptions {
|
|
4805
|
+
maxSize: number;
|
|
4806
|
+
}
|
|
4807
|
+
|
|
4804
4808
|
/**
|
|
4805
4809
|
* A two-tier cache that combines in-memory caching with zone-level caching.
|
|
4806
4810
|
* Data is first checked in memory cache for fastest access, then falls back to
|
|
4807
4811
|
* zone cache if not found. Writes update both cache tiers.
|
|
4808
4812
|
*
|
|
4813
|
+
* The in memory cache is an LRU cache that will evict the least recently used items
|
|
4814
|
+
* when the cache is full. The in memory cache is also periodically purged of
|
|
4815
|
+
* expired items.
|
|
4816
|
+
*
|
|
4817
|
+
* In the event that two MemoryZoneReadThroughCache instances are created
|
|
4818
|
+
* with the same name, they will share the same underlying in-memory cache. This
|
|
4819
|
+
* allows for multiple instances to be created in different parts of the codebase
|
|
4820
|
+
* without having to pass the cache instance around. If two instances are created
|
|
4821
|
+
* with the same name, but different memory cache options, the options of the
|
|
4822
|
+
* first instance created will be used.
|
|
4823
|
+
*
|
|
4824
|
+
*
|
|
4825
|
+
*
|
|
4809
4826
|
* @public
|
|
4810
4827
|
* @example
|
|
4811
4828
|
* ```typescript
|
|
4812
4829
|
* import { MemoryZoneReadThroughCache, ZuploContext } from "@zuplo/runtime";
|
|
4813
4830
|
*
|
|
4814
4831
|
* export async function myHandler(request: ZuploRequest, context: ZuploContext) {
|
|
4832
|
+
* // Create cache with default memory size (1000 items)
|
|
4815
4833
|
* const cache = new MemoryZoneReadThroughCache<UserData>("user-cache", context);
|
|
4816
4834
|
*
|
|
4835
|
+
* // Or create cache with custom memory size (500 items max)
|
|
4836
|
+
* // Note that maxSize controls the number of items in the in-memory cache,
|
|
4837
|
+
* // but does not limit the number of items in the zone cache.
|
|
4838
|
+
* const limitedCache = new MemoryZoneReadThroughCache<UserData>(
|
|
4839
|
+
* "limited-cache",
|
|
4840
|
+
* context,
|
|
4841
|
+
* { maxSize: 500 }
|
|
4842
|
+
* );
|
|
4843
|
+
*
|
|
4817
4844
|
* // Try to get cached data
|
|
4818
4845
|
* const cachedUser = await cache.get("user-123");
|
|
4819
4846
|
* if (cachedUser) {
|
|
@@ -4836,8 +4863,13 @@ export declare class MemoryZoneReadThroughCache<T = unknown> {
|
|
|
4836
4863
|
* Creates a new MemoryZoneReadThroughCache instance.
|
|
4837
4864
|
* @param name - A unique name for this cache instance
|
|
4838
4865
|
* @param context - The ZuploContext from the current request
|
|
4866
|
+
* @param options - Optional configuration for the memory cache
|
|
4839
4867
|
*/
|
|
4840
|
-
constructor(
|
|
4868
|
+
constructor(
|
|
4869
|
+
name: string,
|
|
4870
|
+
context: ZuploContext,
|
|
4871
|
+
options?: MemoryCacheOptions
|
|
4872
|
+
);
|
|
4841
4873
|
/**
|
|
4842
4874
|
* Retrieves a value from the cache by key. First checks memory cache,
|
|
4843
4875
|
* then falls back to zone cache if not found in memory.
|