Skip to main content

Query Memoization

Utilities

Efficiently cache the results of any query in memory for an indicated period of time.

Installation

api('com.psddev.component-lib:query-memoization-util')

Installing this plugin automatically adds the MemoizingDatabase to the database stack. This can be disabled by setting dari/isQueryMemoizationEnabled to false or per request with the query parameter ?_cache=false

Note that queries are not cached by default; each query must be opted in explicitly.

Usage


class Test {
void main() {

int memoizationSeconds = 60;
Query query = Query.from(Article.class).where("x = y");

// Enable memoization on this query
MemoizingDatabase.setMemoizationSeconds(query, memoizationSeconds);

// The results of this query are efficiently cached in memory for 60
// seconds across all requests.
PaginatedResult<Article> results = query.select(0, 10);
}
}