From 96dc25a031db00d59d4289b8f8c6bbe831a02a04 Mon Sep 17 00:00:00 2001 From: mahsa shadi <mahsa.shadi@mail.um.ac.ir> Date: Tue, 2 Aug 2022 15:03:32 +0430 Subject: [PATCH] Add VFS capability caching --- src/vfs.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/vfs.js b/src/vfs.js index 8277402..79f8782 100644 --- a/src/vfs.js +++ b/src/vfs.js @@ -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, @@ -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; + }); +}; /**