Caching Data from an External Database, RPC Server, or Public Window

Sybase CEP Engine sometimes experiences delays when evaluating database subqueries and remote subqueries. To eliminate this delay, set caching preferences to enable Sybase CEP Server to cache values received from external databases and remote servers.

Sybase CEP Engine is optimized to evaluate CCL statements very quickly. However, database subqueries (which join a Sybase CEP Server data stream to an external relational database table or to a public window) and remote subqueries (which join the Sybase CEP Engine data stream to a remote procedure call server) can significantly slow query execution if every row in the data stream is sent to an external database or remote procedure server.

To eliminate this delay, Sybase CEP Server caches values received from external databases and remote servers. When database, public window, or remote procedure data is cached, Sybase CEP Server only queries the external database, public window, or RPC server when a new row arrives in the joined data stream and the cache no longer contains a matching queryresult. Otherwise, Sybase CEP Server uses the result stored in the cache, and does not send the row to the external database, remote server, or public window.

The following three preferences control the operation of the cache. Sybase CEP Engine uses these preferences only in conjunction with direct CCL connection to a database, remote server, or public window. Adapters do not use these preferences:

You can set these caching preferences either within the c8-services.xml file, or by using the CCL CACHE clause, inside a database subquery, or remote subquery. If you set caching preferences in both places, Sybase CEP Engine uses the settings of your CACHE clause, and ignores the settings in the c8-services.xml file. You can also set the CACHE clause to clear the cache whenever a row arrives in a specified data stream or named window, regardless of the caching policies. For more information, see the "CACHE Clause" section of the Sybase CEP CCL Reference Guide .

"CacheMaximumAge" determines whether caching takes place and specifies the time interval during which data from the database subquery, RPC server, or public window is cached. See the Sybase CEP CCL Reference Guide for more information about supported interval specifications. The maximum setting for this preference is 100 years. If you set "CacheMaximumAge" to 0, or do not specify this preference, then Sybase CEP Server does not cache data and all other caching preferences are ignored. If you specify a value of -1, caching is infinite with respect to age, in which case you must set another caching preference to limit the cache size in another way.

As a general rule, if the data in the database, public window or RPC server changes infrequently and you have enough memory to cache the data, then you should enable data caching and set to a longer interval. However, if the data changes frequently and you need the most up-to-date data possible, then you should set caching to a short duration or disable it completely.

In the following example, "CacheMaximumAge" is set to 30 seconds. This means that, for any CCL rows received by the query within the 30 seconds, Sybase CEP Engine retrieves the value for the corresponding database, public window, or RPC value from the cache, instead of sending it to and retrieving it from the database, public window, or RPC service itself.

<Param Name="CacheMaximumAge">30 SECONDS</Param>
Note: Sybase CEP Server does not automatically detect when an external database table or public window is updated or when data changes on the RPC server. The database or RPC server does not inform Sybase CEP Engine about updates and Sybase CEP Server does not "poll" the external server for changes. Sybase CEP Server only queries the external server when a new row arrives in a Sybase CEP Engine stream and the data in the cache has expired.

"CacheMaximumMemoryUsage" controls the cache contents based on the size of the cache. This preference specifies a maximum number of bytes for the cache. The default value is 0 (unlimited). This preference can be set to an integer of any size to specify the maximum number of bytes for the cache. The value is specified as a 32-bit integer on 32-bit systems, or as a 64-bit integer on 64-bit systems. Sybase CEP Engine enforces the maximum byte size separately for every database subquery or remote subquery.

When the cache exceeds the size you specified, Sybase CEP Engine begins deleting items from the cache from least to most-recently used, until it removes enough items to bring cache size below the maximum. The following example sets the maximum cache size for each database subquery, remote subquery, or public window to one Megabyte (1Mb).

<Param Name="CacheMaximumMemoryUsage">1048576</Param>
Note: Since "CacheMaximumMemoryUsage" limits the cache to an actual number of bytes, consider issues such as data fragmentation when setting this preference.

"CacheMaximumSize" limits the size of the cache to the specified number of rows. The default value is 0 (unlimited). You can also set this preference to an integer of any size (taking into account your system's limitations) to specify the maximum number of rows the cache can hold. Sybase CEP Engine enforces the maximum row number separately for every database subquery, remote subquery, or public window.

When the cache exceeds the number of rows you specify, Sybase CEP Engine begins deleting rows, from least to most-recently used, until it removes enough items to bring cache size below the maximum. The following example sets the maximum number of rows in the cache to 100 for every database subquery, remote subquery, or public window.

<Param Name="CacheMaximumSize">100</Param>

Cache policies set by "CacheMaximumAge", "CacheMaximumMemoryUsage", and "CacheMaximumSize" interact in the following way:

"CacheMaximumAge" Setting

"CacheMaximumMemoryUsage" Setting

"CacheMaximumSize" Setting

Comments

-1

0 or omitted (defaults to 0)

0 or omitted (defaults to 0)

Not permitted. If you set "CacheMaximumAge" to infinite size, you must limit the cache by byte size and/or number of rows. Sybase does not permit unbounded infinite caching.

-1

positive integer

0 or omitted

Cache is limited by maximum number of bytes only.

-1

0 or omitted

positive integer

Cache is limited by maximum number of rows only.

-1

positive integer

positive integer

Cache is limited by maximum number of bytes and maximum number of rows.

0 or omitted (defaults to 0)

any setting

any setting

Caching is turned off. "CacheMaximumMemoryUsage" and "CacheMaximumSize" settings (if any) are ignored.

interval specification

0 or omitted

0 or omitted

Cache is limited by row age only.

interval specification

0 or omitted

positive integer

Cache is limited by row age and number of rows in the cache.

interval specification

positive integer

0 or omitted

Cache is limited by row age and byte size.

interval specification

positive integer

positive integer

Cache is limited by row age, byte size and number of rows.

Caching preferences affect only the service for which you specify them.