ExcelWorkbookCache

io.github.quafadas.scautable.ExcelWorkbookCache

Thread-safe cache for Excel workbook instances to avoid file contention and improve performance.

This cache uses weak references to allow workbooks to be garbage collected when no longer needed, while providing significant performance improvements when multiple operations access the same Excel file.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def cacheSize: Int

Get the current number of cached workbook references.

Get the current number of cached workbook references.

Note that this includes weak references that may have been garbage collected. This method is primarily useful for testing and debugging.

Attributes

Returns

The number of cached workbook references

def clearAll(): Unit

Clear the entire cache and attempt to close all cached workbooks.

Clear the entire cache and attempt to close all cached workbooks.

This is primarily useful for testing or application shutdown.

Attributes

def closeAndRemove(filePath: String): Unit

Explicitly close and remove a workbook from the cache.

Explicitly close and remove a workbook from the cache.

This method should be called when you know a workbook will no longer be needed to free up resources immediately rather than waiting for garbage collection.

Value parameters

filePath

The path to the Excel file

Attributes

def getOrCreate(filePath: String): Try[Workbook]

Get or create a workbook for the specified file path.

Get or create a workbook for the specified file path.

This method is thread-safe and will reuse existing workbook instances when possible. If a workbook is garbage collected, a new one will be created automatically.

Value parameters

filePath

The absolute path to the Excel file

Attributes

Returns

A Try containing the Workbook instance, or a Failure if the file cannot be opened