Class BitwardenCacheManager

java.lang.Object
com.mwdle.bitwarden.BitwardenCacheManager

@Extension public class BitwardenCacheManager extends Object
A thread-safe singleton that manages the lifecycle of the Bitwarden item metadata cache.

This class is the single source of truth for the list of credentials from Bitwarden. It handles asynchronous refreshing, persistence to disk for resilience, and provides safe, non-blocking access for the Jenkins UI and other components.

  • Constructor Details

    • BitwardenCacheManager

      public BitwardenCacheManager()
  • Method Details

    • getInstance

      public static BitwardenCacheManager getInstance()
      Provides global access to the single instance of this manager.
      Returns:
      The singleton instance of BitwardenCacheManager.
    • updateCache

      public void updateCache()
      Triggers a non-destructive, asynchronous refresh of the cache. This is the standard method for forcing an update from Bitwarden.
    • invalidateCache

      public void invalidateCache()
      Completely removes the credential list from the in-memory cache. The next request for credentials will trigger a full, but non-blocking reload.

      Credential requests that occur during a full reload will receive an empty list of credentials, until the cache has finished repopulating.

    • triggerStartupCacheUpdate

      @Initializer(after=SYSTEM_CONFIG_ADAPTED) public void triggerStartupCacheUpdate()
      Schedules a background task to update the Bitwarden item cache after Jenkins starts.

      This method is automatically invoked by Jenkins's startup sequence. It only proceeds if the plugin has been configured. The update is submitted to a background thread to ensure this operation does not block or delay the main Jenkins startup process.

    • getMetadata

      public List<BitwardenItemMetadata> getMetadata()
      Provides a safe, non-blocking way to get the current list of credential metadata.

      This method returns the current cached data immediately (or an empty list if not yet populated) and triggers a background refresh if the data is stale or missing.

      Returns:
      The current list of BitwardenItemMetadata, which may be empty.