blob: 062cd2ed935f536de7468142e689ee7415ed6fbd [file] [log] [blame]
---
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
title: Custom Query Cache Provider
url: /docs/3.0/custom-query-cache-provider.html
layout: docs_legacy
---
<P>By default Cayenne stores cached query results in an LRUMap (<TT>'org.apache.cayenne.cache.MapQueryCacheFactory'</TT>) and can also be configured to use OSCache (via <TT>'org.apache.cayenne.cache.OSQueryCacheFactory'</TT>). If none of these cache engines suit specific application needs, users can hook up their own. </P>
<P>Assuming you have some cache management library that you want to integrate with Cayenne, you need to implement a <TT>'org.apache.cayenne.cache.QueryCacheFactory'</TT> interface that creates an instance of <TT>'org.apache.cayenne.cache.QueryCache'</TT> that is a facade to your cache engine.</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">class MyFactory <SPAN class="code-keyword">implements</SPAN> QueryCacheFactory {
<SPAN class="code-keyword">public</SPAN> QueryCache getQueryCache(Map properties) {
<SPAN class="code-keyword">return</SPAN> <SPAN class="code-keyword">new</SPAN> MyQueryCache(properties);
}
}
</PRE>
</DIV></DIV>
<P>Custom factory can be set on the DataDomain:</P>
<DIV class="code panel" style="border-width: 1px;"><DIV class="codeContent panelContent">
<PRE class="code-java">DataDomain domain = Configuration.getSharedConfiguration().getDomain();
domain.setQueryCacheFactory(<SPAN class="code-keyword">new</SPAN> MyFactory());
</PRE>
</DIV></DIV>
<P><EM>TODO: pending <A href="https://issues.apache.org/cayenne/browse/CAY-825" class="external-link" rel="nofollow">CAY-825 implementation</A>, setting custom factory should be possible via CayenneModeler.</EM> </P>