From 75e8ea383c40e28982d0f6c773c6926634663908 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 2 Nov 2018 09:52:05 +0000 Subject: [PATCH] rc: implement rc.PutCachedFs for prefilling the remote cache --- fs/rc/cache.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/rc/cache.go b/fs/rc/cache.go index af3aac230..dd9896ce3 100644 --- a/fs/rc/cache.go +++ b/fs/rc/cache.go @@ -48,6 +48,21 @@ func GetCachedFs(fsString string) (f fs.Fs, err error) { return entry.f, err } +// PutCachedFs puts an fs.Fs named fsString into the cache +func PutCachedFs(fsString string, f fs.Fs) { + fsCacheMu.Lock() + defer fsCacheMu.Unlock() + fsCache[fsString] = &cacheEntry{ + f: f, + fsString: fsString, + lastUsed: time.Now(), + } + if !expireRunning { + time.AfterFunc(cacheExpireInterval, cacheExpire) + expireRunning = true + } +} + // cacheExpire expires any entries that haven't been used recently func cacheExpire() { fsCacheMu.Lock()