Computer apparatus and method for caching results of a database query
First Claim
1. An apparatus comprising:
- at least one processor;
a memory coupled to the at least one processor;
a database residing in the memory;
a query processor residing in the memory and executed by the at least one processor, the query processor caching data retrieved from the database as a result of a first query, and returning cached data when processing a second query to the database instead of accessing data in the database; and
a data staleness handler that determines from a specified parameter in the second query whether use of cached data is enabled when processing the second query and does not return the cached data when processing the second query if a specified range of values for using the cached data is not satisfied or if the specified parameter specifies that use of cached data is disabled when processing the second query.
1 Assignment
0 Petitions
Accused Products
Abstract
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.
110 Citations
33 Claims
-
1. An apparatus comprising:
-
at least one processor; a memory coupled to the at least one processor; a database residing in the memory; a query processor residing in the memory and executed by the at least one processor, the query processor caching data retrieved from the database as a result of a first query, and returning cached data when processing a second query to the database instead of accessing data in the database; and a data staleness handler that determines from a specified parameter in the second query whether use of cached data is enabled when processing the second query and does not return the cached data when processing the second query if a specified range of values for using the cached data is not satisfied or if the specified parameter specifies that use of cached data is disabled when processing the second query. - View Dependent Claims (2, 3, 4, 5, 6, 7, 8, 9)
-
-
10. An apparatus comprising:
-
at least one processor; a memory coupled to the at least one processor; a database residing in the memory; a cache residing in the memory; a query processor residing in the memory and executed by the at least one processor, the query processor storing data retrieved from the database into the cache as a result of a first query, and returning data from the cache when processing a second query to the database instead of accessing the data in the database if specified conditions for returning the cached data are satisfied; a data staleness handler residing in the memory and executed by the at least one processor, wherein the data staleness handler indicates to the query processor when the cached data cannot be returned, wherein the data staleness handler indicates to the query processor that the cached data cannot be returned when processing the second query if use of cached data is disabled in the second query, wherein the data staleness handler indicates to the query processor that the cached data cannot be returned during a specified range of times, wherein the data staleness handler indicates to the query processor that the cached data cannot be returned during a specified range of dates, wherein the data staleness handler monitors selected data in the database that corresponds to at least a portion of the cached data and invalidates the cached data when the selected data in the database changes, wherein the data staleness handler uses a timer to invalidate the cached data when the timer times out, wherein the data staleness handler updates the cached data by retrieving the changed data from the database into the cache when the cached data is invalidated.
-
-
11. A computer-implemented method for processing a second query to a database, the method comprising the steps of
(A) processing a first query to the database by performing the steps of (A1) retrieving data from the database that satisfies the first query; -
(A2) storing the retrieved data in a cache; and (A3) returning the retrieved data; (B) processing the second query by performing the steps of (B1) determining from a specified parameter in the second query whether use of cached data is allowed in processing the second query; (B2) determining whether the second query is capable of being satisfied by data stored in the cache; (B3) determining whether use of cached data is allowed depending on whether a specified range of values for using the cache is satisfied; (B4) if the query is capable of being satisfied by data stored in the cache and the use of cached data is allowed, retrieving data from the cache that satisfies the second query, and returning the data retrieved from the cache; (B5) if the query is not capable of being satisfied by data stored in the cache, retrieving data from the database that satisfies the second query, and returning the data that satisfies the second query; (B6) if the use of cached data is not allowed as determined instep (B1), retrieving data from the database that satisfies the second query, and returning the retrieved data that satisfies the second query. - View Dependent Claims (12, 13, 14, 15, 16, 17, 18)
-
-
19. A computer-implemented method for processing a second query to a database, the method comprising the steps of:
-
(A) processing a first query to the database by performing the steps of; (A1) retrieving data from the database that satisfies the first query; (A2) storing the retrieved data in a cache; and (A3) returning the retrieved data; (B) processing the second query by performing the steps of; (B1) determining whether the second query is capable of being satisfied by data stored in the cache; (B2) determining whether caching is disabled in the second query; (B3) determining whether the second query specifies a range of times during which use of the cached data is not allowed; (B4) determining whether the second query specifies a range of dates during which use of the cached data is not allowed; (B5) if the query is capable of being satisfied by data stored in the cache, if step (B2) indicates that caching is not disabled, and if steps (B3) and (B4) indicate that use of the cached data is allowed, retrieving the data from the cache that satisfies the second query and returning the data that satisfies the second query; (B6) if the query is not capable of being satisfied by data stored in the cache, retrieving data from the database that satisfies the second query, and returning the data that satisfies the second query; (B7) if step (B2) indicates that caching is disabled in the second query, retrieving data from the database that satisfies the second query, and returning the retrieved data that satisfies the second query; and (B8) if either of steps (B3) and (B4) indicate that use of the cached data is not allowed, retrieving data from the database and returning the data retrieved from the database. - View Dependent Claims (20, 21, 22, 23)
-
-
24. A program product comprising:
-
(A) a query processor that caches data retrieved from a database as a result of a first query, and returns cached data when processing a second query to the database instead of accessing data in the database wherein the query processor includes a data staleness handler that determines from a specified parameter in the second query whether use of cached data is enabled when processing the second query and does not return the cached data when processing the second query if a specified range of values for using the cached data is not satisfied or if the specified parameter specifies that use of cached data is disabled when processing the second query; and (B) recordable computer-readable signal bearing media bearing the query processor. - View Dependent Claims (25, 26, 27, 28, 29, 30, 31, 32)
-
-
33. A program product comprising:
-
(A) a query that stores data retrieved from a database into a cache as a result of a first query, and returns data from the cache when processing a second query to the database instead of accessing the data in the database if specified conditions for returning the cached data are satisfied; (B) a data staleness handler that indicates to the query processor when the cached data cannot be returned, wherein the data staleness handler indicates to the query processor that the cached data cannot be returned when processing the second query if use of cached data is disabled in the second query, wherein the data staleness handler indicates to the query processor that the cached data cannot be returned during a specified range of times, wherein the data staleness handler indicates to the query processor that the cached data cannot be returned during a specified range of dates, wherein the data staleness handler monitors selected data in the database that corresponds to at least a portion of the cached data and invalidates the cached data when the selected data in the database changes, wherein the data staleness handler uses a timer to invalidate the cached data when the timer times out, wherein the data staleness handler updates the cached data by retrieving the changed data from the database into the cache when the cached data is invalidated; and (C) recordable computer-readable signal bearing media bearing the query processor and the data staleness handler.
-
Specification