@Override
    public <T> ISignalWriteStream putBinary(final String cacheKey, final T jsonObject, final long timeToLive)
            throws IOException {
        final IApimanBuffer buffer = bufferFactory.createBuffer();
        synchronized (mapMutex) {
            expireOnMap.put(cacheKey, System.currentTimeMillis() + (timeToLive * 1000));
            objectCache.put(cacheKey, jsonObject);
            dataCache.put(cacheKey, buffer);
        }
        return new ISignalWriteStream() {
            private boolean finished = false;
            @Override
            public void abort(Throwable t) {
                finished = true;
            }
            @Override
            public boolean isFinished() {
                return finished;
            }
            @Override
            public void write(IApimanBuffer chunk) {
                buffer.append(chunk);
            }
            @Override
            public void end() {
                finished = true;
                synchronized (cacheSizeMutex) {
                    cacheSize += buffer.length();
                    if (cacheSize > maxCacheSize) {
                        synchronized (mapMutex) {
                            while (cacheSize > maxCacheSize) {
                                String cacheKey = objectCache.keySet().iterator().next();
                                objectCache.remove(cacheKey);
                                expireOnMap.remove(cacheKey);
                                IApimanBuffer removedBuffer = dataCache.remove(cacheKey);
                                if (removedBuffer != null) {
                                    cacheSize -= removedBuffer.length();
                                }
                            }
                        }
                    }
                }
            }
        };
    }
@see io.apiman.gateway.engine.components.ICacheStoreComponent#putBinary(java.lang.String, java.lang.Object, long)
gateway/engine/core/src/main/java/io/apiman/gateway/engine/impl/InMemoryCacheStoreComponent.java