Skip to Content

How to take advantage of server-side cache

Printer-friendly versionSend to friendPDF version
Intermediate
This tutorial explains how to store rich media data in cache, granting a more immediate access to such content while it remains valid, and thus improving the user experience by reducing latency.
Server cache mechanism is indeed available in order to make it possible to deliver a content to the client more rapidly, by sorting processed content or external resources.

Principle

Streamezzo framework provides straightforward facilities to cache content remotely on server (improved delivery time to multiple devices).

 

On server-side, 2 cache levels can be exploited with advantage:

  • processed scenes caching (level 1), i.e. the currently processed scene result is delivered to requesting client and is also stored in server cache, so that next clients requesting the same content can have it delivered immediately, without any processing delay (as long as this content has not reached a specified expiration time)
  • external resources caching (level 2), i.e. the distant resources (media) required for the currently requested scene processing can be stored in server cache, so that the next processing delay will be reduced accordingly, getting rid of the external resources download delay (as long as they have not reached a specified expiration time)

Features

Rich Media content (scene) that is dynamically processed server-side can be stored in server cache (on device) for faster access to this remote content, getting rid of the processing latency itself.

In addition it is also possible to stored in server cache external resources that can be necessary for the processing, for immediate access to those resources, thus reducing the overall processing time.

Processed scene caching (level 1)

Cache level 1 enables storing server-side the result of a Rich Media Content processing (i.e. binary data obtained for processed RSP). While this stored content remains valid it will not be necessary it to process it a each request from client, only to retrieve the stored result, this being applicable for the initially requesting device but also for all other devices for which the processed content remains relevant.

A specific directive in server-side scenes enables to activate and configure storage in server cache level 1: one has to set in the following attributes in the Streamezzo tag:

  • serverCacheTtl: specifies the server cache entry time to live (TTL), in milliseconds (default) / seconds (s) / hours (h) / days (d); when specified activates server cache level 1 (i.e. if no serverCacheTTL is specified in the Streamezzo tag, no server cache level 1 is applied)

External resource caching (level 2)

Cache level 2 enables storing server-side downloaded external resources, so that next requests / next processings of RSP do not require again waiting for those resources to be downloaded, thus inducing extra processing time and, finally, extra latency from the end-user's point of view.

A specific directive in server-side scenes enables to activate and configure storage in server cache level 2 for all tags related to media: one has to set in the following attributes either the image or Bitmap or BasicMediaStream or Full3GPMediaStream or Three3GPMediaStream or Video or Audio  tags:

  • servCacheTtl: specifies the server cache entry time to live (TTL), in milliseconds (default) / seconds (s) / hours (h) / days (d); when specified activates server cache level 2 for this media resource (i.e. if no servCacheTTL is specified in those tags, no server cache level 2 is applied)

Cache storage

Streamezzo Rich Media Server cache (level 1 and 2) entries can be stored either in memory or database:

  • database: low speed access but easy to manage and is shared among all RMS nodes within the cluster
  • memory: high speed access but located into RMS node itself (note: cannot be managed through Rich Media Server administration interface)

This can be configured from Streamezzo Rich Media Server administration interface (Management > Edit settings > Tuning).

Database cache is usually used on developments platforms.

Memory cache is based on ehcache framework and is more efficient in terms of access time and is usually used onproduction platforms.

Remote cache management

Streamezzo Rich Media Server cache (level 1 and 2) entries can be managed remotely (i.e. from an external Content Management System (CMS), for example) through HTTP thanks to either:

  • HTTP/XML API: relies on HTTP requests sent to Rich Media Server administration and returning a XML message in response
  • web service: supposed to be implemented by Rich Media Server administration

The management operations granted from outside Streamezzo Rich Media Server administration interface itself are:

  • level 1
    • removal of all expired cached scenes
    • removal all cached scene
    • prefetch a scene in cache, i.e. without even requiring a first access from a client; this is granted through HTTP/XML API only
  • level 2
    • removal of a specific cached resource
    • removal of all expired cached resources
    • removal of all cached resources

Streamezzo Rich Media Server comes with a Java client giving access to an API designed so that a Java CMS could easily include those features.

The complete Streamezzo Rich Media Server documentation for remote cache management is available here.

Debugging

Checking what is stored in server cache or not, when and when it becomes deprecated (TTL expiration) is necessary to ensure the available cached content is accurate at anytime and the end-user experience is fully optimized, either storing full processed response (level 1) or downloaded external resources (level 2).

In order to make it possible and easy to check the server cache (level 1 and 2) effectiveness and current state, one can rely on those facilities:

  • logs: specific logs are automatically generated with INFO or DEBUG level when storing and accessing entries in server cache; they are available in Workbench Developer Emulator logs view and in Streamezzo Rich Media Server administration interface logs page (if the log level is currently set so that such logs are generated)
    • storing in cache level 1:
      • [...] INFO  Emulated_Service : Saving service response as cache
      • [...] DEBUG Emulated_Service : Saving cache : __rspfile__=level_1.rsp, 10000 [...]
      • [...] DEBUG Emulated_Service : Cache data size : [...]
    • accessing cache level 1:
      • [...] DEBUG Emulated_Service : Cache entry found [...]
    • storing in cache level 2:
      • [...] INFO  Emulated_Service : Searching cached resource for Resource [...]
      • [...] INFO  Emulated_Service : No cached resource found for Resource [...]
      • [...] INFO  Emulated_Service : Creating a cached resource for Resource [...]
    • accessing cache level 2:
      • [...] INFO  Emulated_Service : Searching cached resource for Resource [...]
      • [...] INFO  Emulated_Service : Found a cached resource for Resource [...]
  • cache content views (tables): dedicated pages on Streamezzo Rich Media Server administration interface enable to list current entries for both cache levels; from there it is possible to:
    • list current entries (URL)
    • clear one specific entry
    • clear expired entries
    • clear all entries
  •  

Examples

In the simple examples provided below, all scenes are of course server-side scenes, which processing result can be stored in cache on server.

Processed scene caching (level 1)

The following simple code sample illustrates how to store a currently accessed scene in server cache. Next accesses to this scene do not require processing, as long as the specified TTL has not expired.

The sample code is available here.

External resource caching (level 2)

The following simple code sample illustrates how to store a media required to by a currently accessed scene in server cache. Next accesses to this scene will require processing but will no suffer from media download latency, as long as the specified TTL has not expired.

The sample code is available here.

Remote cache management

The following simple Java code illustrates how to remove a scene from server-side cache (level 1), remove an external resources from server-side cache (level 2) and prefetch a scene in server-side cache (level 1), thanks to the provided API.

It assumes one has properly set the configuration to access Streamezzo Rich Media Server instance in the provided stzManager.properties file.

InputStream in; RemoteManager remoteCacheManager; // Initialize try { in = new FileInputStream("conf/stzManager.properties"); } catch (FileNotFoundException fnfe) { System.out.println("Manager properties not found: "+fnfe.getMessage()); return; } try { remoteCacheManager = RemoteManagerFactory.getRemoteManager(in); } catch (Exception ce) { System.out.println("Remove manager instanciation failed: "+ce.getMessage()); return; } // Cached scene removal if (action == CACHED_SCENE_REMOVAL) { try { remoteCacheManager.removeCachedScene("level_1.rsp", "a=1&b=2"); } catch (RemoteManagerException rme) { System.out.println("Cached scene removal failed: "+rme.getMessage()); return; } } // Cached resource removal if (action == CACHED_RESOURCE_REMOVAL) { try { remoteCacheManager.removeCachedResource("http://developer.streamezzo.com/sites/default/files/images/stz_logo.png"); } catch (RemoteManagerException rme) { System.out.println("Cached resource removal failed: "+rme.getMessage()); return; } } // Cache scene prefetching if (action == CACHED_SCENE_PREFETCHING) { try { System.out.println(remoteCacheManager.prefetchCachedScene("/um_level1servercache", "STZ/6.03.09 (snz=1272359309 kbz=52 SES=1 w=240 h=320 d=[Acer_DX650] os=[Windows NT/6.1] m=00740FFF c=16777216 p=RM)")); } catch (RemoteManagerException rme) { System.out.println("Cached scene prefetching failed: "+rme.getMessage()); return; } }

Note that for the prefetching it is necessary to specify an URL Mapping for the scene to be addressed (this can be configured in Streamezzo Rich Media Server administration interface > Profiles > list > edit - see screenshot below) and it can be convenient to intercept the required User-Agent string, which is especially displayed in Streamezzo Rich Media Server administration interface > Services > logs when accessing a scene for a given mobile phone).

Share this