01-11-2011 04:07 AM
01-11-2011 06:42 AM
01-11-2011 07:54 AM
MyBatis has includes a powerful query caching feature which is very configurable and customizable.
A lot of changes have been made in the MyBatis 3 cache implementation to make it both more powerful and far easier to configure.
By default, there is no caching enabled, except for local session caching, which improves performance and is required to resolve circular dependencies. To enable a second level of caching, you simply need to add one line to your SQL Mapping file:
<cache/>
Literally that’s it. The effect of this one simple statement is as follows:
• All results from select statements in the mapped statement file will be cached.
• All insert, update and delete statements in the mapped statement file will flush the cache.
• The cache will use a Least Recently Used (LRU) algorithm for eviction.
• The cache will not flush on any sort of time based schedule (i.e. no Flush Interval).
• The cache will store 1024 references to lists or objects (whatever the query method returns).
• The cache will be treated as a read/write cache, meaning objects retrieved are not shared and can be safely modified by the caller, without interfering with other potential modifications by other callers or threads.
All of these properties are modifiable through the attributes of the cache element. For example:
<cache eviction="FIFO" flushInterval="60000" size="512" readOnly="true"/>
This more advanced configuration creates a FIFO cache that flushes once every 60 seconds, stores up to 512 references to result objects or lists, and objects returned are considered read-only, thus modifying them could cause conflicts between callers in different threads.
The available eviction policies available are: LRU, FIFO, WEAK
Using a Custom Cache
In addition to customizing the cache in these ways, you can also completely override the cache behavior by implementing your own cache, or creating an adapter to other 3rd party caching solutions.
<cache type=”com.domain.something.MyCustomCache”/>
01-11-2011 08:37 AM
01-11-2011 09:54 AM
putting the entity ONLY in the queue is not a good idea. as the mgmt service wants to show the backlog jobs.
but you could consider storing the already-locked job it in the table AND then putting the whole object on the queue.
then just pushing the whole job object on the queue is i believe a simple form of caching that you're looking for. right?
i don't recall any mybatis caching similar to hibernate's second level cache.
01-11-2011 10:03 AM
I added the "<cache/>"-tag to job.mapping.xml but still got an extra "select job"-query for when the job was to be executed. I tested this by running the "OneMessageTest.java" (available in attached jobcache.zip) and looking at the queries.log of my local MySQL database.
I've added an extra jobCache to DbSqlSession which does prevent the extra select-query (see "jobCache-changes.txt" in attached jobcache.zip). This does the trick but I'm not sure this is a proper solution
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.