Skip to content

Commit b064408

Browse files
authored
chore(commons): extract lru-cache into commons (aws-powertools#2899)
1 parent a9d4a9c commit b064408

File tree

6 files changed

+25
-9
lines changed

6 files changed

+25
-9
lines changed

Diff for: packages/commons/package.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
"import": "./lib/esm/fromBase64.js",
4646
"require": "./lib/cjs/fromBase64.js"
4747
},
48+
"./utils/lru-cache": {
49+
"import": "./lib/esm/LRUCache.js",
50+
"require": "./lib/cjs/LRUCache.js"
51+
},
4852
"./types": {
4953
"import": "./lib/esm/types/index.js",
5054
"require": "./lib/cjs/types/index.js"
@@ -60,6 +64,10 @@
6064
"lib/cjs/fromBase64.d.ts",
6165
"lib/esm/fromBase64.d.ts"
6266
],
67+
"utils/lru-cache": [
68+
"lib/cjs/LRUCache.d.ts",
69+
"lib/esm/LRUCache.d.ts"
70+
],
6371
"types": [
6472
"lib/cjs/types/index.d.ts",
6573
"lib/esm/types/index.d.ts"
@@ -88,4 +96,4 @@
8896
"devDependencies": {
8997
"@aws-lambda-powertools/testing-utils": "file:../testing"
9098
}
91-
}
99+
}

Diff for: packages/idempotency/src/persistence/LRUCache.ts renamed to packages/commons/src/LRUCache.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { LRUCacheOptions } from '../types/LRUCache.js';
1+
import type { LRUCacheOptions } from './types/LRUCache.js';
22

33
const DEFAULT_MAX_SIZE = 100;
44
const NEWER = Symbol('newer');
@@ -213,7 +213,7 @@ class LRUCache<K, V> {
213213
*/
214214
private trackItemUse(item: Item<K, V>): void {
215215
// If the item is already the newest, we don't need to do anything
216-
if (this.mostRecentlyUsed === item) return; // TODO: check this
216+
if (this.mostRecentlyUsed === item) return;
217217

218218
// If the item is not the newest, we need to mark it as the newest
219219
if (item[NEWER]) {
File renamed without changes.

Diff for: packages/idempotency/tests/unit/persistence/LRUCache.test.ts renamed to packages/commons/tests/unit/LRUCache.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
22
* Test LRUCache class
33
*
4-
* @group unit/idempotency/persistence/lru-cache
4+
* @group unit/commons/lru-cache
55
*/
6-
import { LRUCache } from '../../../src/persistence/LRUCache.js';
6+
import { LRUCache } from '../../src/LRUCache.js';
77

88
describe('Class: LRUMap', () => {
99
describe('Method: add', () => {

Diff for: packages/commons/typedoc.json

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
{
2-
"extends": ["../../typedoc.base.json"],
3-
"entryPoints": ["./src/index.ts", "./src/types/index.ts"],
2+
"extends": [
3+
"../../typedoc.base.json"
4+
],
5+
"entryPoints": [
6+
"./src/index.ts",
7+
"./src/types/index.ts",
8+
"./src/typeUtils.ts",
9+
"./src/fromBase64.ts",
10+
"./src/LRUCache.ts"
11+
],
412
"readme": "./README.md"
5-
}
13+
}

Diff for: packages/idempotency/src/persistence/BasePersistenceLayer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { type Hash, createHash } from 'node:crypto';
22
import type { JSONValue } from '@aws-lambda-powertools/commons/types';
3+
import { LRUCache } from '@aws-lambda-powertools/commons/utils/lru-cache';
34
import { search } from '@aws-lambda-powertools/jmespath';
45
import type { JMESPathParsingOptions } from '@aws-lambda-powertools/jmespath/types';
56
import { EnvironmentVariablesService } from '../config/EnvironmentVariablesService.js';
@@ -15,7 +16,6 @@ import type {
1516
BasePersistenceLayerOptions,
1617
} from '../types/BasePersistenceLayer.js';
1718
import { IdempotencyRecord } from './IdempotencyRecord.js';
18-
import { LRUCache } from './LRUCache.js';
1919

2020
/**
2121
* Base class for all persistence layers. This class provides the basic functionality for

0 commit comments

Comments
 (0)