Skip to content
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

chore(commons): extract lru-cache into commons #2899

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
"import": "./lib/esm/fromBase64.js",
"require": "./lib/cjs/fromBase64.js"
},
"./utils/lru-cache": {
"import": "./lib/esm/LRUCache.js",
"require": "./lib/cjs/LRUCache.js"
},
"./types": {
"import": "./lib/esm/types/index.js",
"require": "./lib/cjs/types/index.js"
Expand All @@ -60,6 +64,10 @@
"lib/cjs/fromBase64.d.ts",
"lib/esm/fromBase64.d.ts"
],
"utils/lru-cache": [
"lib/cjs/LRUCache.d.ts",
"lib/esm/LRUCache.d.ts"
],
"types": [
"lib/cjs/types/index.d.ts",
"lib/esm/types/index.d.ts"
Expand Down Expand Up @@ -88,4 +96,4 @@
"devDependencies": {
"@aws-lambda-powertools/testing-utils": "file:../testing"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LRUCacheOptions } from '../types/LRUCache.js';
import type { LRUCacheOptions } from './types/LRUCache.js';

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

// If the item is not the newest, we need to mark it as the newest
if (item[NEWER]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Test LRUCache class
*
* @group unit/idempotency/persistence/lru-cache
* @group unit/commons/lru-cache
*/
import { LRUCache } from '../../../src/persistence/LRUCache.js';
import { LRUCache } from '../../src/LRUCache.js';

describe('Class: LRUMap', () => {
describe('Method: add', () => {
Expand Down
14 changes: 11 additions & 3 deletions packages/commons/typedoc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"extends": ["../../typedoc.base.json"],
"entryPoints": ["./src/index.ts", "./src/types/index.ts"],
"extends": [
"../../typedoc.base.json"
],
"entryPoints": [
"./src/index.ts",
"./src/types/index.ts",
"./src/typeUtils.ts",
"./src/fromBase64.ts",
"./src/LRUCache.ts"
],
"readme": "./README.md"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type Hash, createHash } from 'node:crypto';
import type { JSONValue } from '@aws-lambda-powertools/commons/types';
import { LRUCache } from '@aws-lambda-powertools/commons/utils/lru-cache';
import { search } from '@aws-lambda-powertools/jmespath';
import type { JMESPathParsingOptions } from '@aws-lambda-powertools/jmespath/types';
import { EnvironmentVariablesService } from '../config/EnvironmentVariablesService.js';
Expand All @@ -15,7 +16,6 @@ import type {
BasePersistenceLayerOptions,
} from '../types/BasePersistenceLayer.js';
import { IdempotencyRecord } from './IdempotencyRecord.js';
import { LRUCache } from './LRUCache.js';

/**
* Base class for all persistence layers. This class provides the basic functionality for
Expand Down