LRU.js — react Source File
Architecture documentation for LRU.js, a javascript file in the react codebase. 1 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 57da4469_3808_3be7_cda2_0920208b9c2a["LRU.js"] cf0374be_82da_b932_450f_9145a907b064["scheduler"] 57da4469_3808_3be7_cda2_0920208b9c2a --> cf0374be_82da_b932_450f_9145a907b064 8ab83c6a_7f7f_de7c_f120_e86a1c481f9e["ReactCacheOld.js"] 8ab83c6a_7f7f_de7c_f120_e86a1c481f9e --> 57da4469_3808_3be7_cda2_0920208b9c2a style 57da4469_3808_3be7_cda2_0920208b9c2a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import * as Scheduler from 'scheduler';
// Intentionally not named imports because Rollup would
// use dynamic dispatch for CommonJS interop named imports.
const {
unstable_scheduleCallback: scheduleCallback,
unstable_IdlePriority: IdlePriority,
} = Scheduler;
type Entry<T> = {
value: T,
onDelete: () => mixed,
previous: Entry<T>,
next: Entry<T>,
};
type LRU<T> = {
add(value: Object, onDelete: () => mixed): Entry<Object>,
update(entry: Entry<T>, newValue: T): void,
access(entry: Entry<T>): T,
setLimit(newLimit: number): void,
};
export function createLRU<T>(limit: number): LRU<T> {
let LIMIT = limit;
// Circular, doubly-linked list
let first: Entry<T> | null = null;
let size: number = 0;
let cleanUpIsScheduled: boolean = false;
function scheduleCleanUp() {
if (cleanUpIsScheduled === false && size > LIMIT) {
// The cache size exceeds the limit. Schedule a callback to delete the
// least recently used entries.
cleanUpIsScheduled = true;
scheduleCallback(IdlePriority, cleanUp);
}
}
function cleanUp() {
cleanUpIsScheduled = false;
deleteLeastRecentlyUsedEntries(LIMIT);
}
function deleteLeastRecentlyUsedEntries(targetSize: number) {
// Delete entries from the cache, starting from the end of the list.
if (first !== null) {
const resolvedFirst: Entry<T> = (first: any);
let last: null | Entry<T> = resolvedFirst.previous;
// ... (97 more lines)
Domain
Subdomains
Dependencies
- scheduler
Imported By
Source
Frequently Asked Questions
What does LRU.js do?
LRU.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in LRU.js?
LRU.js defines 3 function(s): cleanUp, deleteLeastRecentlyUsedEntries, scheduleCleanUp.
What does LRU.js depend on?
LRU.js imports 1 module(s): scheduler.
What files import LRU.js?
LRU.js is imported by 1 file(s): ReactCacheOld.js.
Where is LRU.js in the architecture?
LRU.js is located at packages/react-cache/src/LRU.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-cache/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free