+2006-03-12 Vince Darley <vincentdarley@sourceforge.net>
+
+ * library/ftpvfs.tcl: provide caching of listings to improve
+ performance for many standard use cases.
+
2006-02-27 Jean-Claude Wippler <jcw@equi4.com>
* library/mkclvfs.tcl: Small optimization so a writable starkit
package require vfs 1.0
package require ftp
-namespace eval vfs::ftp {}
+namespace eval vfs::ftp {
+ # Number of milliseconds for which to cache listings
+ variable cacheListingsFor 1000
+}
proc vfs::ftp::Mount {dirurl local} {
set dirurl [string trim $dirurl]
proc vfs::ftp::_findFtpInfo {fd name} {
::vfs::log "findFtpInfo $fd $name"
- set ftpList [ftp::List $fd [file dirname $name]]
+ set ftpList [cachedList $fd [file dirname $name]]
foreach p $ftpList {
foreach {pname other} [_parseListLine $p] {}
if {$pname == [file tail $name]} {
return ""
}
+proc vfs::ftp::cachedList {fd dir} {
+ variable cacheList
+ variable cacheListingsFor
+
+ # Caches response to prevent going back to the ftp server
+ # for common use cases: foreach {f} [glob *] { file stat $f s }
+ if {[info exists cacheList($dir)]} {
+ return $cacheList($dir)
+ }
+ set listing [ftp::List $fd $dir]
+
+ set cacheList($dir) $listing
+ after $cacheListingsFor [list unset -nocomplain ::vfs::ftp::cacheList($dir)]
+ return $listing
+}
+
# Currently returns a list of name and a list of other
# information. The other information is currently a
# list of:
}
} else {
# matching all files in the given directory
- set ftpList [ftp::List $fd $path]
+ set ftpList [cachedList $fd $path]
::vfs::log "ftpList: $ftpList"
foreach p $ftpList {