Class PersistentLicenseCache

java.lang.Object
org.codehaus.mojo.license.download.PersistentLicenseCache

public class PersistentLicenseCache extends Object
A cache of downloaded license texts that outlives the build. One file per URL, named after the SHA-256 of the URL, holds a small header (URL, download time, content type, validators) followed by the bytes exactly as the server sent them. Because everything is in one file, replacing it with an atomic move is enough for builds that share the cache directory: a reader sees the old entry or the new one, never half of either.
Since:
2.8.0
  • Constructor Details

    • PersistentLicenseCache

      public PersistentLicenseCache(Path directory, Duration timeToLive, boolean readEnabled)
      Parameters:
      directory - where the entries live; created on the first write
      timeToLive - how long an entry is served without asking the server
      readEnabled - when false, find(String) finds nothing, but store(String, byte[], String, String, String) still refreshes the entries
  • Method Details

    • getDirectory

      public Path getDirectory()
    • find

      Parameters:
      url - the final download URL
      Returns:
      the entry for url, fresh or not, or null if there is none, it cannot be read or reading is disabled
    • isFresh

      public boolean isFresh(PersistentLicenseCache.Entry entry)
      Parameters:
      entry - an entry returned by find(String)
      Returns:
      true if entry may be used without asking the server
    • store

      public void store(String url, byte[] body, String contentType, String etag, String lastModified)
      Writes the entry for url, replacing an older one. A failure to write is logged and otherwise ignored: the cache is an optimization.
    • refresh

      public void refresh(PersistentLicenseCache.Entry entry)
      Restarts the time to live of entry after the server confirmed it.
    • record

      public void record(PersistentLicenseCache.Source source)
    • count

      public int count(PersistentLicenseCache.Source source)