Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Case Analysis of cacheModel attribute of iBATIS Cache

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you an example analysis of iBATIS cache cacheModel properties. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.

The iBATIS cache model can be used in Mapped Statement to cache commonly used data in memory. The property cacheModel defines the cache for the query mapped statement. Each query mapped statement can use a different or the same cacheModel. Here is an example:

< cacheModel id= "product-cache" imlementation= "LRU" > < flushInterval hours= "24" / > < flushOnExecute statement= "insertProduct" / > < flushOnExecute statement= "updateProduct" / > < flushOnExecute statement= "deleteProduct" / > < property name= "size" value= "1000" / > < statement id= "getProductList" parameterClass= "int" cacheModel= "product-cache" > select * from PRODUCT where PRD_CAT_ID = # value# < / statement >

In the above example, the cache for "getProductList" uses the WEAK reference type, which is refreshed every 24 hours, or when an update occurs.

Cache Model uses plug-ins to support different caching algorithms. Its implementation is specified in the cacheModel with the type attribute (as shown above). The specified implementation class must implement the CacheController interface, or one of the following four aliases. Other configuration parameters implemented by Cache Model are set through the property element of cacheModel. Currently includes the following four implementations:

◆ "MEMORY" (com.ibatis.db.sqlmap.cache.memory.MemoryCacheController). The MEMORY cache implementation uses reference types to manage the behavior of cache. The garbage collector can determine whether to reclaim the data in the cache based on the reference type. MEMORY implementation is suitable for applications that do not have a unified object reuse pattern, or applications that are out of memory.

◆ "LRU" (com.ibatis.db.sqlmap.cache.lru.LruCacheController). The LRU Cache implementation uses the principle of "least recent use" to determine how to purge objects from Cache. When Cache overflows, the least recently used objects are purged from the Cache. With this approach, if a particular object is always used, it will remain in the Cache and will be least likely to be cleared. LRU Cache is a good choice for situations where certain objects are frequently used by some users over a long period of time (for example, paging in PaginatedList and common query keyword result sets).

◆ "FIFO" (com.ibatis.db.sqlmap.cache.fifo.FifoCacheController). The FIFO Cache implementation uses the "first-in, first-out" principle to determine how to clear objects from the Cache. When the Cache overflows, the objects that enter the Cache will be purged from the Cache. FIFO Cache is a good choice for situations where specific queries are referenced continuously for a short period of time and are likely to be no longer used.

◆ "OSCACHE" (com.ibatis.db.sqlmap.cache.oscache.OSCacheController). The OSCACHE Cache implementation is a Plugin of the OSCache2.0 caching engine. It is highly configurable, distributed and flexible.

The above is the example analysis of the iBATIS cache cacheModel attribute shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report