Server-side image cache

WebCharts 3D image generation engine implements resource pooling and image caching as it is described below:

  1. When the image request is received, the component looks up the image in the image cache using the request parameters as the key. If the image is not found, it is generated and is assigned a unique ID. The image (existing or new) is stamped with the current date and time. The requests that return a pointer to the image (for example, as an image tag) increment the reference count of the image by one. This reference count tells the Image Server how many pages requested the image's url, but never actually retrieved it. Note, that the requests that dispatch the image immediately do not change the reference count.
  2. When the request for the stored image is received, it looks up the image by it's unique ID and returns its bytes. If the reference count is positive, it is decreased by one.
  3. Garbage collector checks the images in the image cache. An image is deleted from the image cache when:

    a) Its reference count is zero and the time since the last request for this image exceeds MinTimeout. MinTimeout allows image server to avoid regenerating images that are often requested.

    b) The time since the last request for this image exceeds MaxTimeout. MaxTimeout allows image server to remove the "dead" images. For example, if the browser requested the page and the image was generated, but the client opted to close the browser and the image was never actually dispatched, then this image will have a positive reference count and will be purged after MaxTimeout expires.

    NOTE. Server side tags and MxServerComponent's getDefaultInstance function automatically call garbage collection. If you use other methods to generate the image you should call gc() function manually.

    NOTE. When a component is destroyed as a result of the system garbage collection it destroys all cached images both in the memory and on the disk. (In other words, when you do not have any references left to the component it will destroy all the  images). 

    NOTE. The cacheSize parameter limits the maximum number of the images stored in the cache simultaneously. The least recently used image will be removed automatically when the new image is placed into the full cache.