All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.whaleal.icefrog.cache.file.LFUFileCache Maven / Gradle / Ivy

The newest version!
package com.whaleal.icefrog.cache.file;

import java.io.File;

import com.whaleal.icefrog.cache.Cache;
import com.whaleal.icefrog.cache.impl.LFUCache;

/**
 *  使用LFU缓存文件,以解决频繁读取文件引起的性能问题
 * @author Looly
 * @author wh
 *
 */
public class LFUFileCache extends AbstractFileCache{
	private static final long serialVersionUID = 1L;

	/**
	 * 构造
* 最大文件大小为缓存容量的一半
* 默认无超时 * @param capacity 缓存容量 */ public LFUFileCache(int capacity) { this(capacity, capacity / 2, 0); } /** * 构造
* 默认无超时 * @param capacity 缓存容量 * @param maxFileSize 最大文件大小 */ public LFUFileCache(int capacity, int maxFileSize) { this(capacity, maxFileSize, 0); } /** * 构造 * @param capacity 缓存容量 * @param maxFileSize 文件最大大小 * @param timeout 默认超时时间,0表示无默认超时 */ public LFUFileCache(int capacity, int maxFileSize, long timeout) { super(capacity, maxFileSize, timeout); } @Override protected Cache initCache() { return new LFUCache(LFUFileCache.this.capacity, LFUFileCache.this.timeout) { private static final long serialVersionUID = 1L; @Override public boolean isFull() { return LFUFileCache.this.usedSize > this.capacity; } @Override protected void onRemove(File key, byte[] cachedObject) { usedSize -= cachedObject.length; } }; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy