org.codehaus.cake.cache.policy.paging.LFUReplacementPolicy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cake-cache-api Show documentation
Show all versions of cake-cache-api Show documentation
This library contains class that are used across all Cake projects
The newest version!
/*
* Copyright 2008 Kasper Nielsen.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://cake.codehaus.org/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.codehaus.cake.cache.policy.paging;
import static org.codehaus.cake.cache.CacheEntry.HITS;
import org.codehaus.cake.cache.CacheEntry;
import org.codehaus.cake.cache.policy.spi.AbstractHeapReplacementPolicy;
/**
*
* However, the LFU policy has a number of drawbacks: it requires logarithmic implementation complexity in cache size,
* pays little attention to recent history, and does not adapt well to changing access patterns since it accumulates
* stale pages with high frequency counts that may no longer be useful.
*
* @param
* the type of keys maintained by the cache
* @param
* the type of values maintained by the cache
*/
public class LFUReplacementPolicy extends AbstractHeapReplacementPolicy {
/** A unique policy name. */
public static final String NAME = "LFU";
public LFUReplacementPolicy() {
// This is used to make sure that the cache will lazy register the HITS attribute
// if the user has not already done so using CacheAttributeConfiguration#add(Attribute...)}
dependSoft(HITS);
}
@Override
protected int compareEntry(CacheEntry o1, CacheEntry o2) {
return HITS.compare(o1, o2);
}
@Override
public void touch(CacheEntry entry) {
siftDown(entry);// hits has been incremented
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy