Hi
I am trying to use https://adobe-consulting-services.github.io/acs-aem-commons/features/http-cache/subpages/base-config... for storing JSON object. Can someone provide a working example. I tried using
https://adobe-consulting-services.github.io/acs-aem-commons/features/http-cache/subpages/creating-ca...
for custom cache store.
Also I tried
https://adobe-consulting-services.github.io/acs-aem-commons/features/http-cache/subpages/activating-...
Not sure if I how to configure it correctly.
I am getting Nullpointer exception in CaffeineMemHttpCacheStoreImpl.
I have added following configuration in code -
com.adobe.acs.commons.httpcache.store.caffeine.impl.CaffeineMemHttpCacheStoreImpl.xml
com.adobe.acs.commons.httpcache.config.impl.HttpCacheConfigImpl-mycode.xml -
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @vsps
ACS AEM Commons Http Cache Store to store a JSON object:
@Component(service = KeyValueCacheStore.class, property = { KeyValueCacheStore.KEY_VALUE_CACHE_TYPE_PROPERTY + "=" + "my-json-cache" }) public class MyJsonCacheStore extends AbstractKeyValueCacheStore<JSONObject> { @Override protected JSONObject getValue(String key) { // Get the JSON object from the cache return getCache().getIfPresent(key); } @Override protected void putValue(String key, JSONObject value) { // Store the JSON object in the cache getCache().put(key, value); } @Override protected Cache<String, JSONObject> createCache() { // Create a new cache with the desired configuration return Caffeine.newBuilder() .expireAfterWrite(1, TimeUnit.HOURS) .maximumSize(1000) .build(); } }
<?xml version="1.0" encoding="UTF-8"?> <jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" jcr:primaryType="sling:OsgiConfig" httpcache.config.order="1000" httpcache.config.requesturi.patterns="[(.*)]" httpcache.config.request.authentication="both" httpcache.config.expiry.on.create="{Long}50000" cacheStoreType="my-json-cache"/>
@Reference private HttpCacheStore httpCacheStore; public void storeJson(String url, JSONObject json) { // Store the JSON object in the cache httpCacheStore.put(url, json, Collections.emptyMap()); } public JSONObject getJson(String url) { // Get the JSON object from the cache return httpCacheStore.get(url, JSONObject.class); }
Regarding the Nullpointer exception in CaffeineMemHttpCacheStoreImpl, it's possible that the configuration is not set up correctly or there is an issue with the cache store implementation.
Hi @vsps
ACS AEM Commons Http Cache Store to store a JSON object:
@Component(service = KeyValueCacheStore.class, property = { KeyValueCacheStore.KEY_VALUE_CACHE_TYPE_PROPERTY + "=" + "my-json-cache" }) public class MyJsonCacheStore extends AbstractKeyValueCacheStore<JSONObject> { @Override protected JSONObject getValue(String key) { // Get the JSON object from the cache return getCache().getIfPresent(key); } @Override protected void putValue(String key, JSONObject value) { // Store the JSON object in the cache getCache().put(key, value); } @Override protected Cache<String, JSONObject> createCache() { // Create a new cache with the desired configuration return Caffeine.newBuilder() .expireAfterWrite(1, TimeUnit.HOURS) .maximumSize(1000) .build(); } }
<?xml version="1.0" encoding="UTF-8"?> <jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" jcr:primaryType="sling:OsgiConfig" httpcache.config.order="1000" httpcache.config.requesturi.patterns="[(.*)]" httpcache.config.request.authentication="both" httpcache.config.expiry.on.create="{Long}50000" cacheStoreType="my-json-cache"/>
@Reference private HttpCacheStore httpCacheStore; public void storeJson(String url, JSONObject json) { // Store the JSON object in the cache httpCacheStore.put(url, json, Collections.emptyMap()); } public JSONObject getJson(String url) { // Get the JSON object from the cache return httpCacheStore.get(url, JSONObject.class); }
Regarding the Nullpointer exception in CaffeineMemHttpCacheStoreImpl, it's possible that the configuration is not set up correctly or there is an issue with the cache store implementation.
Thanks for replay @RajaReddy_3370
Tried to use above code. But none of classes are resolved. I tried adding
in core/pom -
@vsps Did you find the suggestion helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.
Views
Replies
Total Likes
Thanks @Raja_Reddy @kautuk_sahni it worked for me. Earlier my local instance was not building correctly. Removing .m2 folder and rebuilding helped.
Views
Likes
Replies
Views
Likes
Replies