Example #1
0
 /**
  * Creates a cache span from an underlying cache file.
  *
  * @param file The cache file.
  * @return The span, or null if the file name is not correctly formatted.
  */
 public static CacheSpan createCacheEntry(File file) {
   Matcher matcher = cacheFilePattern.matcher(file.getName());
   if (!matcher.matches()) {
     return null;
   }
   return CacheSpan.createCacheEntry(
       matcher.group(1), Long.parseLong(matcher.group(2)), Long.parseLong(matcher.group(3)), file);
 }
 @Override
 public int compare(CacheSpan lhs, CacheSpan rhs) {
   long lastAccessTimestampDelta = lhs.lastAccessTimestamp - rhs.lastAccessTimestamp;
   if (lastAccessTimestampDelta == 0) {
     // Use the standard compareTo method as a tie-break.
     return lhs.compareTo(rhs);
   }
   return lhs.lastAccessTimestamp < rhs.lastAccessTimestamp ? -1 : 1;
 }
Example #3
0
 /**
  * Renames the file underlying this cache span to update its last access time.
  *
  * @return A {@link CacheSpan} representing the updated cache file.
  */
 public CacheSpan touch() {
   long now = System.currentTimeMillis();
   File newCacheFile = getCacheFileName(file.getParentFile(), key, position, now);
   file.renameTo(newCacheFile);
   return CacheSpan.createCacheEntry(key, position, now, newCacheFile);
 }