FileCache

Introduction

FileCache mainly caches small files in the form of byte[] in memory to reduce file access and solve performance issues caused by frequent file reads.

Implementation

  • LFUFileCache
  • LRUFileCache

Usage

// Parameter 1: capacity, the number of bytes that can be accommodated
// Parameter 2: maximum file size, the number of bytes that determine how many files can be cached, files larger than this value will not be cached and will be read directly
// Parameter 3: timeout, in milliseconds
LFUFileCache cache = new LFUFileCache(1000, 500, 2000);
byte[] bytes = cache.getFileBytes("d:/a.jpg");

The usage of LRUFileCache is consistent with LFUFileCache, and will not be demonstrated separately.