UNPKG

als-store

Version:

Library for streamlined file management and advanced data caching, featuring intelligent file searching, dynamic cache control, and flexible file operations

28 lines (20 loc) 1.76 kB
### Method: `values()` #### Overview: The `values()` method is used to enable the retrieval of file content in the `Store` class. This method configures the store to load the content of each file when the `get()` method is called. #### Caching: - **Cache Size**: The content of each file retrieved by this method is cached. The size of this cache is configurable and plays a crucial role in the performance and memory usage of the application. - **Cache Behavior**: Once the cache reaches its set limit, older entries may be evicted to make room for new ones, following a cache eviction policy (e.g., Least Recently Used). #### Asynchronous File Reading: - **Parallel Processing**: The reading of file contents is performed asynchronously, allowing for non-blocking I/O operations. - **Grouped Processing**: By default, files are read in parallel in groups of 100 processes at a time. This parallelism is managed to optimize performance while avoiding excessive resource usage. #### Customizing Parallelism: - **Adjustable Parallel Promises**: The number of parallel processes can be customized by modifying the `Store.paralelPromises` static property. - **Example Usage**: Setting `Store.paralelPromises = 50` would change the parallel processing to handle 50 files at a time. #### Method Implementation: - **Enabling Values**: By invoking this method (`values()`), the store is configured to load and cache the contents of files when `get()` is executed. - **Asynchronous Behavior**: The method ensures that file content loading is done asynchronously, maintaining application responsiveness. ### Usage Example: ```js const store = new Store({ dirPath: '/path/to/dir' }); const {results,errors} = await store.values().get() ```