DatabaseBlobStorage implements BlobStorage { public void deleteExpired() { int deletedCount; do { PageRequest pageable = PageRequest.of(0, 500); List<Long> expired = mBlobRepository.findExpiredBlobIds(pageable); if (!expired.isEmpty()) { deletedCount = mBlobRepository.deleteByIds(expired); logger.debug("Number of Mbob deleted: {}", deletedCount); } else { logger.debug("Nothing to delete"); deletedCount = 0; } } while (deletedCount > 0); } DatabaseBlobStorage(DatabaseBlobStorageConfigurationProperties databaseBlobStorageConfigurationProperties,
                               MBlobRepository mBlobRepository); @Override void put(String name, byte[] content, Retention retention); @Override Optional<byte[]> getBytes(String name); void deleteExpired();  }
@Test public void testCleanup() { DateTime now = DateTime.now(); MBlob notExperied = new MBlob(); notExperied.setCreatedDate(now); notExperied.setExpireAfterSeconds(1000); notExperied = mBlobRepository.save(notExperied); MBlob experied = new MBlob(); experied.setCreatedDate(now.minusDays(1)); experied.setExpireAfterSeconds(1000); experied = mBlobRepository.save(experied); databaseBlobStorage.deleteExpired(); assertNull(mBlobRepository.findById(experied.getId()).orElse(null)); assertNotNull(mBlobRepository.findById(notExperied.getId()).orElse(null)); }