Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tcl/main.tcl.in
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,20 @@ if {[catch {
rename ::__initStateClockSeconds ::initStateClockSeconds
rename ::__parseDateTimeArg ::parseDateTimeArg
}
# wrap getFilesInDirectory with in-memory cache to avoid redundant
# directory reads within a single modulecmd invocation
rename ::getFilesInDirectory ::_getFilesInDirectoryUncached
proc getFilesInDirectory {dir fetch_dotversion} {
set cachekey $dir:$fetch_dotversion
if {[info exists ::g_filesInDirCache($cachekey)]} {
return $::g_filesInDirCache($cachekey)
}
set result [_getFilesInDirectoryUncached $dir $fetch_dotversion]
set ::g_filesInDirCache($cachekey) $result
return $result
}
##nagelfar syntax readFile x x? x?
##nagelfar syntax _getFilesInDirectoryUncached x x
##nagelfar syntax getFilesInDirectory x x
##nagelfar syntax initStateUsergroups
##nagelfar syntax initStateUsername
Expand Down
31 changes: 31 additions & 0 deletions testsuite/modules.90-avail/025-memcache.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
##############################################################################
# Modules Revision 3.0
# Providing a flexible user environment
#
# Description: In-memory cache for getFilesInDirectory
# Command: avail
# Modulefiles: loc_rc1, loc_fq
#
# Test that the in-memory directory read cache returns correct results
# when the same modulepath is queried multiple times within a single
# invocation. The cache wraps getFilesInDirectory so repeated avail
# calls on overlapping paths must produce identical results.
#
##############################################################################

# test that consecutive avail queries return consistent results
# first query populates the cache, second should hit it
set ts2 "$modpath:\nloc_rc1/1.0(foo)\nloc_rc1/2.0"
testouterr_cmd "sh" "avail -t loc_rc1" "OK" $ts2

# second query on same path exercises the cache
testouterr_cmd "sh" "avail -t loc_fq" "OK" $ts1

skip_if_quick_mode

# query a different module in the same modulepath
set ts2 "$modpath:\nloc_rc1/1.0(foo)"
testouterr_cmd "sh" "avail -t loc_rc1" "OK" $ts2

# unset local variables
unset ts1 ts2