Skip to content

Commit 9097d34

Browse files
committed
chore: move cache types out
1 parent 2946741 commit 9097d34

4 files changed

Lines changed: 15 additions & 23 deletions

File tree

packages/snap/src/core/caching/InMemoryCache.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,13 @@ import { assert } from '@metamask/utils';
33
import type { Serializable } from '../serialization/types';
44
import type { ILogger } from '../utils/logger';
55
import type { ICache } from './ICache';
6-
7-
export type TimestampMilliseconds = number;
8-
9-
/**
10-
* A single cache entry.
11-
*/
12-
export type CacheEntry = {
13-
value: Serializable;
14-
expiresAt: TimestampMilliseconds;
15-
};
6+
import type { CacheEntry } from './types';
167

178
/**
18-
* A simple in-memory cache implementation, primarily used for testing purposes.
9+
* A simple in-memory cache implementation supporting TTL (Time To Live) functionality.
1910
*
2011
* WARNINGS:
2112
* - This cache is not persistent and will be lost when the process is restarted.
22-
* - It now supports TTL (Time To Live) functionality.
2313
*/
2414
export class InMemoryCache implements ICache<Serializable> {
2515
#cache: Map<string, CacheEntry> = new Map();

packages/snap/src/core/caching/StateCache.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,7 @@ import type { Serializable } from '../serialization/types';
66
import type { IStateManager } from '../services/state/IStateManager';
77
import type { ILogger } from '../utils/logger';
88
import type { ICache } from './ICache';
9-
10-
export type TimestampMilliseconds = number;
11-
12-
/**
13-
* A single cache entry.
14-
*/
15-
export type CacheEntry = {
16-
value: Serializable;
17-
expiresAt: TimestampMilliseconds;
18-
};
9+
import type { CacheEntry } from './types';
1910

2011
/**
2112
* The whole cache store.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Serializable } from '../serialization/types';
2+
3+
export type TimestampMilliseconds = number;
4+
5+
/**
6+
* A single cache entry.
7+
*/
8+
export type CacheEntry = {
9+
value: Serializable;
10+
expiresAt: TimestampMilliseconds;
11+
};

packages/snap/src/core/services/assets/AssetsService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('AssetsService', () => {
6464

6565
mockState = new InMemoryState(DEFAULT_UNENCRYPTED_STATE);
6666

67-
mockCache = new InMemoryCache();
67+
mockCache = new InMemoryCache(logger);
6868

6969
stateUpdateSpy = jest.spyOn(mockState, 'update');
7070

0 commit comments

Comments
 (0)