Interface ExpiredEntriesCleaner


public interface ExpiredEntriesCleaner
Interface used by particular ProxyManager implementations to indicate that they support the manual(triggered by user) removing of expired bucket entries.

Typically, this interface is implemented by RDBMS backed proxy-managers where underlying DBMS is not support automatically expiration. And wise versa, this interface never implemented by Redis/JCache integrations, because for such technologies expiration is supported out-of-the box by underlying technology.

  • Method Summary

    Modifier and Type
    Method
    Description
    int
    removeExpired(int batchSize)
    Tries to remove expired bucket entries and put all removed keys to the returned collection.
  • Method Details

    • removeExpired

      int removeExpired(int batchSize)
      Tries to remove expired bucket entries and put all removed keys to the returned collection. It is guaranteed that on call of removeExpired does not remove more than batchSize buckets at once, it also means that returned result always less than or equal to batchSize, so caller needs to analyze the size of returned collection and call removeExpired again if needed.

      Example of usage:

       
          private static final int MAX_TO_REMOVE_IN_ONE_TRANSACTION = 1_000;
          private static final int THRESHOLD_TO_CONTINUE_REMOVING = 50;
      
          // once per day at 4:30 morning
          @Scheduled(cron = "0 30 4 * * *")
          public void scheduleFixedDelayTask() {
             int removedKeysCount;
             do {
                  removedCount = proxyManager.removeExpired(MAX_TO_REMOVE_IN_ONE_TRANSACTION);
                  if (removedKeysCount > 0) {
                      logger.info("Removed {} expired buckets", removedCount);
                  } else {
                      logger.info("There are no expired buckets to remove");
                  }
             } while (removedCount > THRESHOLD_TO_CONTINUE_REMOVING)
          }
       
       
      Parameters:
      batchSize - specifies how many expired buckets can be deleted in single transaction.
      Returns:
      count of removed keys