-
Notifications
You must be signed in to change notification settings - Fork 49
refactor(cache): separate web-ui-settings cache from payload cache #632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # AppCache | ||
|
|
||
| ## API | ||
|
|
||
| ### `updatePayload(packageName: string, payload: Payload): void` | ||
|
|
||
| Saves an analysis payload for a given package. | ||
|
|
||
| **Parameters**: | ||
| - `packageName` (`string`): Package name (e.g., `"@nodesecure/scanner@6.0.0"`). | ||
| - `payload` (`object`): The analysis result to store. | ||
|
|
||
| > [!NOTE] | ||
| > Payloads are stored in the user's home directory under `~/.nsecure/payloads/` | ||
|
|
||
| ### `getPayload(packageName: string): Payload` | ||
|
|
||
| Loads an analysis payload for a given package. | ||
|
|
||
| **Parameters**: | ||
| `packageName` (`string`): Package name. | ||
|
|
||
| ### `availablePayloads(): string[]` | ||
|
|
||
| Lists all available payloads (package names) in the cache. | ||
|
|
||
| ### `getPayloadOrNull(packageName: string): Payload | null` | ||
|
|
||
| Loads an analysis payload for a given package, or returns `null` if not found. | ||
|
|
||
| **Parameters**: | ||
|
|
||
| - `packageName` (`string`): Package name. | ||
|
|
||
| Returns `null` if not found. | ||
|
|
||
| ### `updatePayloadsList(payloadsList: PayloadsList): Promise<void>` | ||
|
|
||
| Updates the internal MRU/LRU and available payloads list. | ||
|
|
||
| **Parameters**: | ||
|
|
||
| - `payloadsList` (`object`): The new payloads list object. | ||
|
|
||
| ### `payloadsList(): Promise<PayloadsList>` | ||
|
|
||
| Retrieves the current MRU/LRU and available payloads list. | ||
|
|
||
| ### `initPayloadsList(options: InitPayloadListOptions = {}): Promise<void>` | ||
|
|
||
| Initializes the payloads list, optionally resetting the cache. | ||
|
|
||
| **Parameters**: | ||
|
|
||
| - `options` (`object`, *optional*): | ||
| - `logging` (`boolean`, default: `true`): Enable logging. | ||
| - `reset` (`boolean`, default: `false`): If `true`, reset the cache before initializing. | ||
|
|
||
| ### `removePayload(packageName: string): void` | ||
|
|
||
| Removes a payload for a given package from the cache. | ||
|
|
||
| **Parameters**: | ||
| - `packageName` (`string`): Package name. | ||
|
|
||
| ### `removeLastMRU(): Promise<PayloadsList>` | ||
|
|
||
| Removes the least recently used payload if the MRU exceeds the maximum allowed. | ||
|
|
||
| ### `setRootPayload(payload: Payload, options: SetRootPayloadOptions = {}): Promise<void>` | ||
|
|
||
| Sets a new root payload, updates MRU/LRU, and manages cache state. | ||
|
|
||
| **Parameters**: | ||
|
|
||
| - `payload` (`object`): The analysis result to set as root. | ||
| - `options` (`object`): | ||
| - `logging` (`boolean`, default: `true`): Enable logging. | ||
| - `local` (`boolean`, default: `false`): Mark the payload as local. | ||
|
|
||
| ## Interfaces | ||
|
|
||
| ```ts | ||
| interface PayloadsList { | ||
| mru: string[]; | ||
| lru: string[]; | ||
| current: string; | ||
| availables: string[]; | ||
| lastUsed: Record<string, number>; | ||
| root: string | null; | ||
| } | ||
|
|
||
| interface LoggingOption { | ||
| logging?: boolean; | ||
| } | ||
|
|
||
| interface InitPayloadListOptions extends LoggingOption { | ||
| reset?: boolean; | ||
| } | ||
|
|
||
| interface SetRootPayloadOptions extends LoggingOption { | ||
| local?: boolean; | ||
| } | ||
| ``` |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,77 @@ | ||||||
| # FilePersistanceProvider | ||||||
|
||||||
|
|
||||||
| A generic file-based cache provider using [cacache](https://www.npmjs.com/package/cacache) for persistent storage. | ||||||
|
|
||||||
| ## Usage Example | ||||||
|
|
||||||
| ```ts | ||||||
| import { FilePersistanceProvider } from "@nodesecure/cache"; | ||||||
|
|
||||||
| interface MyData { | ||||||
| name: string; | ||||||
| value: number; | ||||||
| } | ||||||
|
|
||||||
| const cache = new FilePersistanceProvider<MyData>("my-cache-key"); | ||||||
|
|
||||||
| // Store data | ||||||
| await cache.set({ name: "example", value: 42 }); | ||||||
|
|
||||||
| // Retrieve data | ||||||
| const data = await cache.get(); | ||||||
| console.log(data); // { name: "example", value: 42 } | ||||||
|
|
||||||
| // Remove data | ||||||
| await cache.remove(); | ||||||
| ``` | ||||||
|
|
||||||
| ## Interfaces | ||||||
|
|
||||||
| ```ts | ||||||
| interface BasePersistanceProvider<T> { | ||||||
|
||||||
| interface BasePersistanceProvider<T> { | |
| interface BasePersistenceProvider<T> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spelling error: "Persistance" should be "Persistence". Update the documentation link to use the corrected filename.