FileCacheKey key = new FileCacheKey(indexName, filename);
if (trace) log.trace("deleting metadata: " + key);
FileMetadata file = (FileMetadata) metadataCache.withFlags(Flag.SKIP_LOCKING).remove(key);
if (file != null) { //during optimization of index a same file could be deleted twice, so you could see a null here
for (int i = 0; i < file.getNumberOfChunks(); i++) {
ChunkCacheKey chunkKey = new ChunkCacheKey(indexName, filename, i);
if (trace) log.trace("deleting chunk: " + chunkKey);
chunksCache.withFlags(Flag.SKIP_REMOTE_LOOKUP, Flag.SKIP_CACHE_LOAD, Flag.SKIP_LOCKING).removeAsync(chunkKey);
}
}
// last operation, as being set as value==0 it prevents others from using it during the