---
title: "Ehcache缓存回收策略"
author: "mgoann"
date: "2009-04-20T16:32:55Z"
tags: []
slug: "ehcache"
draft: false
lastmod: "2009-04-20T16:32:55Z"
id: 371179
url: "https://mgoann.iteye.com/blog/371179"
---

**Ehcache缓存回收策略**

**简介**

 

缓存回收就是当缓存满了的时候，Ehcache会根据指定的策略来清理缓存。这里的缓存回收策略有别与Ehcache中的失效清理策略。失效清理策略是对失效的Element进行批量清理时所采用的策略，最终所有失效的Element都将被清理，只不过是清理的先后顺序不同罢了。Ehcache中缓存的最大Element数是由maxElementsInMemory来指定的。当缓存中的Element个数达到maxElementsInMemory指定的值时，Ehcache会根据具体的策略来清理缓存，默认的策略是LRU（最近最少使用）。

 

磁盘缓存大小默认是没有限制的，不过可通过maxElementsOnDisk来指定。当磁盘缓存达到maxElementsOnDisk指定的值时，Ehcache会清理磁盘中的缓存使用默认策略是LFU（使用频率最低）。

 

**MemoryStore回收策略**

 

MemoryStore支持三种策略：LRU、LFU、FIFO。