# Cache API reference

> Exports of @anymux/cache.

Source: https://anymux-docs.n.yatsyk.com/docs/cache/jsdoc

## Classes

### CachedFileSystem

Wraps an IFileSystem and caches read operations.
Write operations invalidate relevant cache entries.

```ts
class CachedFileSystem
```

- `constructor(options: CachedFileSystemOptions): CachedFileSystem`
- `isImplemented(method: string): boolean`
- `clearCache(): void`
- `readFile(path: string, options?: { encoding?: BufferEncoding; flag?: string; } | BufferEncoding): Promise<Buffer | string>`
- `stat(path: string, options?: { bigint?: false; }): Promise<Stats>`
- `stat(path: string, options: { bigint: true; }): Promise<BigIntStats>`
- `stat(path: string, options?: { bigint?: boolean; }): Promise<Stats | BigIntStats>`
- `readdir(path: string, options?: { encoding?: BufferEncoding; withFileTypes?: false; recursive?: boolean; }): Promise<string[]>`
- `readdir(path: string, options: { encoding?: BufferEncoding; withFileTypes: true; recursive?: boolean; }): Promise<Dirent[]>`
- `readdir(path: string, options?: { encoding?: BufferEncoding; withFileTypes?: boolean; recursive?: boolean; }): Promise<string[] | Dirent[]>`
- `exists(path: string): Promise<boolean>`
- `access(path: string, mode?: number): Promise<void>`
- `writeFile(path: string, data: Buffer | string | Uint8Array, options?: { encoding?: BufferEncoding; mode?: number; flag?: string; }): Promise<void>`
- `appendFile(path: string, data: Buffer | string | Uint8Array, options?: { encoding?: BufferEncoding; mode?: number; flag?: string; }): Promise<void>`
- `unlink(path: string): Promise<void>`
- `rename(oldPath: string, newPath: string): Promise<void>`
- `mkdir(path: string, options?: { recursive?: boolean; mode?: number; }): Promise<string | undefined>`
- `rmdir(path: string, options?: { maxRetries?: number; recursive?: boolean; retryDelay?: number; }): Promise<void>`
- `rm(path: string, options?: { force?: boolean; maxRetries?: number; recursive?: boolean; retryDelay?: number; }): Promise<void>`
- `copyFile(src: string, dest: string, mode?: number): Promise<void>`
- `lstat(path: string, options?: { bigint?: false; }): Promise<Stats>`
- `lstat(path: string, options: { bigint: true; }): Promise<BigIntStats>`
- `lstat(path: string, options?: { bigint?: boolean; }): Promise<Stats | BigIntStats>`
- `truncate(path: string, len?: number): Promise<void>`
- `utimes(path: string, atime: string | number | Date, mtime: string | number | Date): Promise<void>`
- `chmod(path: string, mode: string | number): Promise<void>`
- `chown(path: string, uid: number, gid: number): Promise<void>`
- `readlink(path: string, options?: { encoding?: BufferEncoding; }): Promise<string>`
- `symlink(target: string, path: string, type?: "dir" | "file" | "junction"): Promise<void>`
- `link(existingPath: string, newPath: string): Promise<void>`
- `createReadStream(path: string, options?: { encoding?: BufferEncoding; start?: number; end?: number; }): ReadStream`
- `createWriteStream(path: string, options?: { encoding?: BufferEncoding; flags?: string; mode?: number; }): WriteStream`
- `watch(path: string, options?: { encoding?: BufferEncoding; persistent?: boolean; recursive?: boolean; }): FSWatcher`
- `open(path: string, flags?: string | number, mode?: number): Promise<IFileHandle>`
- `opendir(path: string, options?: { encoding?: BufferEncoding; bufferSize?: number; recursive?: boolean; }): Promise<IDir>`
- `realpath(path: string, options?: { encoding?: BufferEncoding; }): Promise<string>`
- `cp(src: string, dest: string, options?: { dereference?: boolean; errorOnExist?: boolean; filter?: (src: string, dest: string) => boolean | Promise<boolean>; force?: boolean; mode?: number; preserveTimestamps?: boolean; recursive?: boolean; verbatimSymlinks?: boolean; }): Promise<void>`
- `mkdtemp(prefix: string, options?: { encoding?: BufferEncoding; }): Promise<string>`
- `statfs(path: string, options?: { bigint?: false; }): Promise<StatFs>`
- `statfs(path: string, options: { bigint: true; }): Promise<BigIntStatFs>`
- `statfs(path: string, options?: { bigint?: boolean; }): Promise<StatFs | BigIntStatFs>`
- `lutimes(path: string, atime: string | number | Date, mtime: string | number | Date): Promise<void>`
- `lchown(path: string, uid: number, gid: number): Promise<void>`
- `lchmod(path: string, mode: string | number): Promise<void>`
- `init(options?: { encoding?: string; }): Promise<void>`

### MemoryCacheStrategy

```ts
class MemoryCacheStrategy
```

- `<T = unknown>(defaultTtl?: number): MemoryCacheStrategy<T>`
- `get(key: string): T | undefined`
- `set(key: string, value: T, ttl?: number): void`
- `delete(key: string): void`
- `clear(): void`

## Interfaces

### CachedFileSystemOptions

```ts
interface CachedFileSystemOptions
```

- `fs: IFileSystem`
- `strategy: CacheStrategy<unknown>`
- `ttl: number`

### CacheStrategy

```ts
interface CacheStrategy
```

- `get(key: string): T | undefined`
- `set(key: string, value: T, ttl?: number): void`
- `delete(key: string): void`
- `clear(): void`
