Adds a data-directory backed cache for parsed character card JSONs via node-persist library, removing the need to constantly re-parse the PNG on /all API calls. This downs the load time of 20000 characters from 62s to s (~x30 boost), given the host device's disk is fast enough.
Notes
Same as for memory cache, the data key is <path-to-file>-<modified-time>, which makes collisions or stale caches hardly (if ever) possible.
This works in conjunction with memory cache, making further reloads even faster.
The default state right now is ENABLED, but it's debatable. I don't see any potential downsides to that.
Cached data is not directly editable. Editing a file would make the hash check fail. This is by design.
The cache is validated on server startup to prune invalid records.
Copilot verbiage
This pull request introduces disk caching for character cards to enhance performance, particularly with large card libraries. The changes involve enabling disk caching in the configuration, updating the server setup to verify the disk cache, and modifying the character card parser to support asynchronous operations.
Performance improvements:
default/config.yaml: Added a new configuration option useDiskCache to enable disk caching for character cards.
server.js: Imported the verifyCharactersDiskCache function and added it to the preSetupTasks to ensure the disk cache is verified during server startup. [1][2]
Asynchronous operations:
src/character-card-parser.js: Modified the parse function to be asynchronous, allowing it to read files using fs.promises.readFile for better performance.
Disk caching implementation:
src/endpoints/characters.js: Added the node-persist library for disk caching and implemented the diskCache object to manage the cache. Introduced the verifyCharactersDiskCache function to prune invalid cache entries and updated readCharacterData and writeCharacterData functions to utilize the disk cache. [1][2][3][4]
Summary
Adds a data-directory backed cache for parsed character card JSONs via node-persist library, removing the need to constantly re-parse the PNG on /all API calls. This downs the load time of 20000 characters from 62s to s (~x30 boost), given the host device's disk is fast enough.
Notes
<path-to-file>-<modified-time>
, which makes collisions or stale caches hardly (if ever) possible.Copilot verbiage
This pull request introduces disk caching for character cards to enhance performance, particularly with large card libraries. The changes involve enabling disk caching in the configuration, updating the server setup to verify the disk cache, and modifying the character card parser to support asynchronous operations.
Performance improvements:
default/config.yaml
: Added a new configuration optionuseDiskCache
to enable disk caching for character cards.server.js
: Imported theverifyCharactersDiskCache
function and added it to thepreSetupTasks
to ensure the disk cache is verified during server startup. [1] [2]Asynchronous operations:
src/character-card-parser.js
: Modified theparse
function to be asynchronous, allowing it to read files usingfs.promises.readFile
for better performance.Disk caching implementation:
src/endpoints/characters.js
: Added thenode-persist
library for disk caching and implemented thediskCache
object to manage the cache. Introduced theverifyCharactersDiskCache
function to prune invalid cache entries and updatedreadCharacterData
andwriteCharacterData
functions to utilize the disk cache. [1] [2] [3] [4]Checklist: