0

I have designed the Data access object mybatis mapper to read the read only data from Mysql database.

 @Mapper
    public interface XYZMapper {
    
        @Select("SELECT TYPES FROM abc  WHERE STORE_ID = #{storeId}  and CUSTOMER_ID = #{customerId}")
        public String getDisabledSubscriptions(@Param("storeId") int storeId, @Param("customerId") int customerId);
    
        @Select("SELECT TYPES as messageTypes, NAME as eventName FROM abc  WHERE STORE_ID = #{storeId}")
        public EventSubscription getEventAllSubscriptions(@Param("storeId") int storeId);

http://mybatis.org/hazelcast-cache/

Above link gives solutions for caching using hazelcast. This is used when we configure mapper as xml file. How can we cache each of the above queries as L2 cache by using annotation mapper

2
  • You basically need @CacheNamespace or @CacheNamespaceRef. See the doc for the details. If there is a corresponding XML mapper (i.e. XYZMapper.xml), you should use either 1) <cache /> and @CacheNamespaceRef or 2) @CacheNamespace and <cache-ref />. Commented Nov 5, 2020 at 8:44
  • Thanks for the suggestion. I have not tried this. I have used an approach which is mentioned in my answer. Its so simple to setup hazelcast mybatis and Spring boot Commented Nov 6, 2020 at 1:18

1 Answer 1

0

Solved the issue in following steps

a) @EnableCaching with SpringBootApplication classes

b) add @Cacheable ("abc") in every database method defined in mapper (that you wanted to cache)

c) Defined hazelcast.yml in resources folder with

hazelcast: network: join: multicast: enabled: true

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.