Hi Sergey,
EhCache works well for me. Hazelcast should too, though I don't have much firsthand experience with it. I created a "caching" branch in one of the examples that shows what needs to be done assuming you are on EhCache [1].
What you did is actually correct. You just need a few tweaks:
1. Add a JCache provider dependency to your POM. E.g.:
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.8.0</version>
</dependency>
2. For cache invalidation to happen on entity changes, annotate your entity with @CacheGroups, using the same cache group you have in your AgRest endpoint ("QwertyCache" in your example, "categories" in mine) :
@CacheGroups("categories")
public class Category extends _Category {
}
Once you do 1 & 2, your caching will work, and the results will stay in the cache until invalidated.
3. To additionally configure cache sizes and expiration policies, add "ehcache.xml" file [2], and let Cayenne know on startup [3]:
URL config = getClass().getClassLoader().getResource("ehcache.xml");
ServerRuntime cayenneRuntime = ServerRuntime.builder()
.addConfig("cayenne-project.xml")
.addModule(b -> JCacheModule.contributeJCacheProviderConfig(b, config.toString()))
.build();
4. While "useSharedCache" should work, I recommend using "useLocalCache". Since all GET operations in AgRest are using the same context, this will be much faster.
HTH
Andrus
[1]
https://github.com/agrestio/agrest-bookstore-example/tree/caching
[2]
https://github.com/agrestio/agrest-bookstore-example/blob/caching/src/main/resources/ehcache.xml
[3]
https://github.com/agrestio/agrest-bookstore-example/blob/caching/src/main/java/org/example/agrest/BookstoreApplication.java
> --
> You received this message because you are subscribed to the Google Groups "Agrest Framework User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
agrest-user...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/agrest-user/2a955282-ca6f-4d69-8a3e-af94e62bec21%40googlegroups.com.