Skip to content

Commit

Permalink
Add VFS capability caching
Browse files Browse the repository at this point in the history
  • Loading branch information
mahsa shadi authored and andersevenrud committed Aug 2, 2022
1 parent 0e38221 commit 587ec89
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/vfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ import {
* @property {object} [stat]
*/

// Cache the capability of each mount point
let capabilityCache = {};

// Makes sure our input paths are object(s)
const pathToObject = path => ({
id: null,
Expand All @@ -81,8 +84,17 @@ const handleDirectoryList = (path, options) => result =>
* @param {VFSMethodOptions} [options] Options
* @return {Promise<object[]>} An object of capabilities
*/
export const capabilities = (adapter, mount) => (path, options = {}) =>
adapter.capabilities(pathToObject(path), options, mount);
export const capabilities = (adapter, mount) => (path, options = {}) => {
const cached = capabilityCache[mount.name];
if (cached) {
return Promise.resolve(cached);
}
return adapter.capabilities(pathToObject(path), options, mount)
.then(res => {
capabilityCache[mount.name] = res;
return res;
});
};


/**
Expand Down

0 comments on commit 587ec89

Please sign in to comment.