Skip to content

Commit 587ec89

Browse files
mahsa shadiandersevenrud
authored andcommitted
Add VFS capability caching
1 parent 0e38221 commit 587ec89

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/vfs.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ import {
6060
* @property {object} [stat]
6161
*/
6262

63+
// Cache the capability of each mount point
64+
let capabilityCache = {};
65+
6366
// Makes sure our input paths are object(s)
6467
const pathToObject = path => ({
6568
id: null,
@@ -81,8 +84,17 @@ const handleDirectoryList = (path, options) => result =>
8184
* @param {VFSMethodOptions} [options] Options
8285
* @return {Promise<object[]>} An object of capabilities
8386
*/
84-
export const capabilities = (adapter, mount) => (path, options = {}) =>
85-
adapter.capabilities(pathToObject(path), options, mount);
87+
export const capabilities = (adapter, mount) => (path, options = {}) => {
88+
const cached = capabilityCache[mount.name];
89+
if (cached) {
90+
return Promise.resolve(cached);
91+
}
92+
return adapter.capabilities(pathToObject(path), options, mount)
93+
.then(res => {
94+
capabilityCache[mount.name] = res;
95+
return res;
96+
});
97+
};
8698

8799

88100
/**

0 commit comments

Comments
 (0)