EhCache Item Size

I set up a simple cache, using Integerfor key and Doublefor value. After the cache cache.calculateInMemorySize() / cache.getMemoryStoreSize()is full, the ratio is constant at 344 bytes per element. I expect overhead, but my payload is (32 + 64) 96 bits or 12 bytes, so the overhead is as much as 332 bytes - or am I completely misunderstood how this works? If not, what if something, can I do to reduce overhead?

The cache is intended for storage only in memory. We want everything to be there, so overflow and expiration are not needed, and since we can quickly populate an external data source (just not fast enough to use it as the main data source), persistence is also not needed.

Using version 2.4.0.

+3
source share
2 answers

I assume that the payload is things that are actually cached. Did you also indicate the size of the keys? I believe that calculateInMemorySize also includes keys.

0
source

Based on your requirements:

The cache is intended for storage only in memory. We want everything there, so overflow and expiration are not needed, and since we can fill up quite quickly from an external data source (just not fast enough to use it as the primary data source), persistence is not necessary either.

, - . HashMap... . , EhCache !

:

public class MyCustomCache
{
  private Map<Integer, Double> myMap = new HashMap<Integer, Double>();

  public Double getCachedValueByKey(Integer key)
  {
    return myMap.get(key);
  }

  public void putValue2Cache(Integer key, Double value)
  {
    myMap.put(key, value);
  }

  public Double removeValueFromCache(Integer key)
  {
    return myMap.remove(key);
  }
}
0

Source: https://habr.com/ru/post/1793871/


All Articles