Codota Logo
CacheLongKeyLIRS
Code IndexAdd Codota to your IDE (free)

How to use
CacheLongKeyLIRS
in
org.h2.mvstore.cache

Best Java code snippets using org.h2.mvstore.cache.CacheLongKeyLIRS (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
List l =
  • Codota Iconnew LinkedList()
  • Codota IconCollections.emptyList()
  • Codota Iconnew ArrayList()
  • Smart code suggestions by Codota
}
origin: com.h2database/h2

/**
 * Set the read cache size in MB.
 *
 * @param mb the cache size in MB.
 */
public void setCacheSize(int mb) {
  final long bytes = (long) mb * 1024 * 1024;
  if (cache != null) {
    cache.setMaxMemory(bytes);
    cache.clear();
  }
  if (cacheChunkRef != null) {
    cacheChunkRef.setMaxMemory(bytes / 4);
    cacheChunkRef.clear();
  }
}
origin: com.h2database/h2

int len = CACHE_BLOCK_SIZE - off;
len = Math.min(len, dst.remaining());
ByteBuffer buff = cache.get(cachePos);
if (buff == null) {
  buff = ByteBuffer.allocate(CACHE_BLOCK_SIZE);
    cache.put(cachePos, buff, CACHE_BLOCK_SIZE);
  } else {
    if (read <= 0) {
origin: com.h2database/h2

/**
 * Get the maximum cache size, in MB.
 * Note that this does not include the page chunk references cache, which is
 * 25% of the size of the page cache.
 *
 * @return the cache size
 */
public int getCacheSize() {
  if (cache == null) {
    return 0;
  }
  return (int) (cache.getMaxMemory() / 1024 / 1024);
}
origin: com.h2database/h2

/**
 * Add an entry to the cache using the average memory size.
 *
 * @param key the key (may not be null)
 * @param value the value (may not be null)
 * @return the old value, or null if there was no resident entry
 */
public V put(long key, V value) {
  return put(key, value, sizeOf(value));
}
origin: com.h2database/h2

/**
 * Get the entry set for all resident entries.
 *
 * @return the entry set
 */
public synchronized Set<Map.Entry<Long, V>> entrySet() {
  HashMap<Long, V> map = new HashMap<>();
  for (long k : keySet()) {
    map.put(k,  find(k).value);
  }
  return map.entrySet();
}
origin: com.h2database/h2

/**
 * Get the value for the given key if the entry is cached. This method
 * adjusts the internal state of the cache sometimes, to ensure commonly
 * used entries stay in the cache.
 *
 * @param key the key (may not be null)
 * @return the value, or null if there is no resident entry
 */
public V get(long key) {
  int hash = getHash(key);
  return getSegment(hash).get(key, hash);
}
origin: com.h2database/h2

private void clearCache(ByteBuffer src, long position) {
  if (cache.size() > 0) {
    int len = src.remaining();
    long p = getCachePos(position);
    while (len > 0) {
      cache.remove(p);
      p += CACHE_BLOCK_SIZE;
      len -= CACHE_BLOCK_SIZE;
    }
  }
}
origin: com.h2database/h2

/**
 * Remove an entry. Both resident and non-resident entries can be
 * removed.
 *
 * @param key the key (may not be null)
 * @return the old value, or null if there was no resident entry
 */
public V remove(long key) {
  int hash = getHash(key);
  int segmentIndex = getSegmentIndex(hash);
  Segment<V> s = segments[segmentIndex];
  // check whether resize is required: synchronize on s, to avoid
  // concurrent resizes (concurrent reads read
  // from the old segment)
  synchronized (s) {
    s = resizeIfNeeded(s, segmentIndex);
    return s.remove(key, hash);
  }
}
origin: com.h2database/h2

/**
 * Put the page in the cache.
 *
 * @param pos the page position
 * @param page the page
 * @param memory the memory used
 */
void cachePage(long pos, Page page, int memory) {
  if (cache != null) {
    cache.put(pos, page, memory);
  }
}
origin: com.h2database/h2

@Override
public synchronized FileChannel truncate(long newSize) throws IOException {
  cache.clear();
  base.truncate(newSize);
  return this;
}
origin: com.h2database/h2

/**
 * Get the amount of memory used for caching, in MB.
 * Note that this does not include the page chunk references cache, which is
 * 25% of the size of the page cache.
 *
 * @return the amount of memory used for caching
 */
public int getCacheSizeUsed() {
  if (cache == null) {
    return 0;
  }
  return (int) (cache.getUsedMemory() / 1024 / 1024);
}
origin: com.h2database/h2

/**
 * Read a page.
 *
 * @param map the map
 * @param pos the page position
 * @return the page
 */
Page readPage(MVMap<?, ?> map, long pos) {
  if (pos == 0) {
    throw DataUtils.newIllegalStateException(
        DataUtils.ERROR_FILE_CORRUPT, "Position 0");
  }
  Page p = cache == null ? null : cache.get(pos);
  if (p == null) {
    Chunk c = getChunk(pos);
    long filePos = c.block * BLOCK_SIZE;
    filePos += DataUtils.getPageOffset(pos);
    if (filePos < 0) {
      throw DataUtils.newIllegalStateException(
          DataUtils.ERROR_FILE_CORRUPT,
          "Negative position {0}", filePos);
    }
    long maxPos = (c.block + c.len) * BLOCK_SIZE;
    p = Page.read(fileStore, pos, map, filePos, maxPos);
    cachePage(pos, p, p.getMemory());
  }
  return p;
}
origin: com.h2database/h2

cache.remove(pos);
origin: com.h2database/h2

  cache = new CacheLongKeyLIRS<>(cc);
  cc.maxMemory /= 4;
  cacheChunkRef = new CacheLongKeyLIRS<>(cc);
} else {
  cache = null;
if (cache != null && pgSplitSize > cache.getMaxItemSize()) {
  pgSplitSize = (int)cache.getMaxItemSize();
origin: com.h2database/h2

private void addToMap(Entry<V> e) {
  int index = getHash(e.key) & mask;
  e.mapNext = entries[index];
  entries[index] = e;
  usedMemory += e.memory;
  mapSize++;
}
origin: org.gridgain/gridgain-indexing

/**
 * Specifies max allowed size of cache for deserialized offheap rows to avoid deserialization costs for most
 * frequently used ones. In general performance is better with greater cache size. Must be more than 128 items.
 *
 * @param size Cache size in items.
 */
@GridSpiConfiguration(optional = true)
public void setMaxOffheapRowsCacheSize(int size) {
  A.ensure(size >= 128, "Offheap rows cache size must be not less than 128.");
  rowCache = new CacheLongKeyLIRS<>(size, 1, 128, 256);
}
origin: com.h2database/h2

/**
 * Get the value for the given key if the entry is cached. This method does
 * not modify the internal state.
 *
 * @param key the key (may not be null)
 * @return the value, or null if there is no resident entry
 */
public V peek(long key) {
  Entry<V> e = find(key);
  return e == null ? null : e.value;
}
origin: com.h2database/h2

/**
 * Check whether the given value is stored.
 *
 * @param value the value
 * @return true if it is stored
 */
public boolean containsValue(Object value) {
  return getMap().containsValue(value);
}
origin: com.h2database/h2

/**
 * Get the values for all resident entries.
 *
 * @return the entry set
 */
public List<V> values() {
  ArrayList<V> list = new ArrayList<>();
  for (long k : keySet()) {
    V value = find(k).value;
    if (value != null) {
      list.add(value);
    }
  }
  return list;
}
origin: com.h2database/h2

/**
 * Check whether there is a resident entry for the given key. This
 * method does not adjust the internal state of the cache.
 *
 * @param key the key (may not be null)
 * @return true if there is a resident entry
 */
public boolean containsKey(long key) {
  int hash = getHash(key);
  return getSegment(hash).containsKey(key, hash);
}
org.h2.mvstore.cacheCacheLongKeyLIRS

Javadoc

A scan resistant cache that uses keys of type long. It is meant to cache objects that are relatively costly to acquire, for example file content.

This implementation is multi-threading safe and supports concurrent access. Null keys or null values are not allowed. The map fill factor is at most 75%.

Each entry is assigned a distinct memory size, and the cache will try to use at most the specified amount of memory. The memory unit is not relevant, however it is suggested to use bytes as the unit.

This class implements an approximation of the the LIRS replacement algorithm invented by Xiaodong Zhang and Song Jiang as described in http://www.cse.ohio-state.edu/~zhang/lirs-sigmetrics-02.html with a few smaller changes: An additional queue for non-resident entries is used, to prevent unbound memory usage. The maximum size of this queue is at most the size of the rest of the stack. About 6.25% of the mapped entries are cold.

Internally, the cache is split into a number of segments, and each segment is an individual LIRS cache.

Accessed entries are only moved to the top of the stack if at least a number of other entries have been moved to the front (8 per segment by default). Write access and moving entries to the top of the stack is synchronized per segment.

Most used methods

  • <init>
    Create a new cache with the given memory size.
  • clear
    Remove all entries.
  • get
    Get the value for the given key if the entry is cached. This method adjusts the internal state of th
  • getMaxMemory
    Get the maximum memory to use.
  • getUsedMemory
    Get the currently used memory.
  • put
    Add an entry to the cache. The entry may or may not exist in the cache yet. This method will usually
  • remove
    Remove an entry. Both resident and non-resident entries can be removed.
  • find
  • getHash
    Get the hash code for the given key. The hash code is further enhanced to spread the values more eve
  • getMap
    Convert this cache to a map.
  • getSegment
  • getSegmentIndex
  • getSegment,
  • getSegmentIndex,
  • keySet,
  • resizeIfNeeded,
  • setMaxMemory,
  • size,
  • sizeOf,
  • getMaxItemSize

Popular in Java

  • Reading from database using SQL prepared statement
  • findViewById (Activity)
  • requestLocationUpdates (LocationManager)
  • orElseThrow (Optional)
  • Color (java.awt)
    The Color class is used encapsulate colors in the default sRGB color space or colors in arbitrary co
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now