public void writeToCache(int sizeToCache, CachedBlock cachedBlock) { // cachedBlock may or may not already have content cached (in case of overwriting); // check what's the actual size of caching that will be added (or even subtracted) int cachingActualSize = 0; if (cachedBlock.getContent() != null) { cachingActualSize = sizeToCache - cachedBlock.getContent().length; } else { cachingActualSize = sizeToCache; } // increase (or even decrease) the amount of total bytes cached totalBytesCached += cachingActualSize; // check if the amount of bytes to be cached requires bytes to be removed from cache if (totalBytesCached > ClientConfigurations.MAX_CACHE_SIZE) { totalBytesCached -= removeXBytesFromCache( totalBytesCached - ClientConfigurations.MAX_CACHE_SIZE, cachedBlock); } // Call the ReplacementPolicy implementation of writeToCache writeToCache(cachedBlock); }