Function Signature
Description
TheReset() function clears the internal cache, forcing the next call to Dir() to re-detect the home directory. This function generally never has to be called in production code, but is useful in specific scenarios like testing.
When to Use
You should callReset() when:
- Testing: When you’re modifying the home directory via environment variables (like
HOME,USERPROFILE) in tests and need to re-detect the directory - Dynamic environments: When the home directory might change during program execution (rare)
- Cache invalidation: After changing environment variables that affect home directory detection
In most production applications, you don’t need to call
Reset(). The cache improves performance and the home directory rarely changes during execution.Parameters
None.Return Values
None. This function does not return any values.Behavior
Reset() clears the cached home directory value by:
- Acquiring a write lock on the cache
- Setting the internal cache to an empty string
- Releasing the lock
Dir() will perform full home directory detection, and the result will be cached again (unless DisableCache is true).
Usage Examples
Testing with Environment Variables
Forcing Re-detection
Multiple Test Cases
Relationship with DisableCache
Reset() and DisableCache serve different purposes:
Reset(): Clears the cache once, forcing the next detection. The result is still cached for subsequent calls.DisableCache = true: Disables caching entirely. Every call toDir()will re-detect the home directory.
Thread Safety
Reset() is thread-safe. It uses a mutex lock to ensure safe concurrent access to the cache.
Related
- Dir() - The function whose cache is cleared by
Reset() - DisableCache - Alternative approach to prevent caching