Skip to content

Commit

Permalink
chore(commons): extract lru-cache into commons (#2899)
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamorosi authored Aug 7, 2024
1 parent a9d4a9c commit b064408
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 9 deletions.
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
File renamed without changes.
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

0 comments on commit b064408

Please sign in to comment.