A query processor caches data retrieved from executing prepared statements, and uses the cached data for subsequent accesses to the data, if certain conditions for using the cached data are met. The preferred embodiments also include a data staleness handler that takes care of issues that arise from data that may have changed in the
database but is not reflected in the cache. One way to
handle data staleness in the cache is to specifically enable or disable caching in a query. If caching is disabled, the query processor will access the data in the
database. Another way to
handle data staleness in the cache is to provide a
timer that causes the cache to be invalidated when the
timer times out. Yet another way to
handle data staleness in the cache is to provide specified conditions that must be met for caching to occur, such as time or date limitations. Still another way to handle data staleness in the cache is to provide an update trigger for the data in the
database that corresponds to the cached data. When the data in the database is updated, the update trigger fires, causing the cache to be invalidated. Note that invalidating the cache could also be followed by automatically updating the cache. By caching the results of
processing a
prepared statement, other queries that use the same
prepared statement may be able to access data in the cache instead of going to the database.