tag:blogger.com,1999:blog-3237724005744642470.post7791768396611435936..comments2020-07-30T12:43:10.297+01:00Comments on Captain Debug's Blog: Spring 3.1 Caching and @Cacheable Roger Hugheshttp://www.blogger.com/profile/07042290171112551665[email protected]Blogger6125tag:blogger.com,1999:blog-3237724005744642470.post-49433197220816825422013-11-09T16:31:42.013+00:002013-11-09T16:31:42.013+00:00Tim Thanks for the comment, it&#39;s a good point,...Tim<br />Thanks for the comment, it&#39;s a good point, though not unexpected and not an error. ApplicationContexts, as far as I&#39;m aware don&#39;t talk to one another, they&#39;re independent, decoupled entities. The clue is in the name <i>Application</i>Context, i.e. there&#39;s usually only one per application. As you know, you define an ApplicationContext using the Spring config XML file. If you need to combine these files to create a larger context then you can use the import directive. For example importing a database context into your main context by doing something like this:<br /><br /> &lt;beans:import resource=&quot;spring-datasource.xml&quot; /&gt;Roger Hugheshttps://www.blogger.com/profile/07042290171112551665[email protected]tag:blogger.com,1999:blog-3237724005744642470.post-72193874154153116702013-11-08T10:14:43.766+00:002013-11-08T10:14:43.766+00:00Roger I found error source: only looks for @Cac...Roger<br /><br />I found error source:<br /><br /> only looks for @Cacheable/@CacheEvict on beans in the same application context it is defined in. This means that, if you put in a WebApplicationContext for a DispatcherServlet, it only checks for @Cacheable/@CacheEvict beans in your controllers, and not your services. <br /><br />I moved cache config to my spring-mvc-config and cahce starts work. To be honest i do not understand how it works. Timhttps://www.blogger.com/profile/17275906006401076040[email protected]tag:blogger.com,1999:blog-3237724005744642470.post-67363505701885786842013-10-24T22:04:25.310+01:002013-10-24T22:04:25.310+01:00Tim Not sure what&#39;s going wrong without lookin...Tim<br />Not sure what&#39;s going wrong without looking at the code. You can see from the log that your initialising a cache called &#39;books&#39;, which should match up with the value attribute of the @Cacheable annotation. It must be down to config, so if you haven&#39;t already, take a look at:<br /><br />/2012/09/spring-31-caching-and-config.html#.UmmJgTK9KK0Roger Hugheshttps://www.blogger.com/profile/07042290171112551665[email protected]tag:blogger.com,1999:blog-3237724005744642470.post-2509034196700852432013-10-23T16:48:31.552+01:002013-10-23T16:48:31.552+01:00Hi Roger. I have some troubles with this annotati...Hi Roger.<br /><br />I have some troubles with this annotation. I think i done all properly, but i getting &quot;cache miss&quot; all the time. It seams that no cache at all. <br />Ehcache config is ok. I see log lines that it starts and i see books.data (my cache name) in temp directory, but size of this file is 0. <br />No error at runtime. <br />I turn on ehcache log leve to all, and see only this messages at starttime:<br /><br />2874 [RMI TCP Connection(2)-127.0.0.1] DEBUG n.s.e.config.ConfigurationHelper - No CacheExceptionHandlerFactory class specified. Skipping... <br />2894 [RMI TCP Connection(2)-127.0.0.1] DEBUG net.sf.ehcache.store.MemoryStore - Initialized net.sf.ehcache.store.MemoryStore for books <br />2903 [RMI TCP Connection(2)-127.0.0.1] DEBUG net.sf.ehcache.DiskStorePathManager - Using diskstore path /Library/Tomcat/temp <br />2903 [RMI TCP Connection(2)-127.0.0.1] DEBUG net.sf.ehcache.DiskStorePathManager - Holding exclusive lock on /Library/Tomcat/temp/.ehcache-diskstore.lock <br />2903 [RMI TCP Connection(2)-127.0.0.1] DEBUG n.s.e.store.disk.DiskStorageFactory - Failed to delete file books.data <br />2903 [RMI TCP Connection(2)-127.0.0.1] DEBUG n.s.e.store.disk.DiskStorageFactory - Failed to delete file books.index <br />2928 [RMI TCP Connection(2)-127.0.0.1] DEBUG n.s.e.store.disk.DiskStorageFactory - Matching data file missing (or empty) for index file. Deleting index file /Library/Tomcat/temp/books.index <br />2928 [RMI TCP Connection(2)-127.0.0.1] DEBUG n.s.e.store.disk.DiskStorageFactory - Failed to delete file books.index <br />2938 [RMI TCP Connection(2)-127.0.0.1] DEBUG net.sf.ehcache.Cache - Initialised cache: books <br />2938 [RMI TCP Connection(2)-127.0.0.1] DEBUG n.s.e.config.ConfigurationHelper - CacheDecoratorFactory not configured. Skipping for &#39;books&#39;. <br />2939 [RMI TCP Connection(2)-127.0.0.1] DEBUG n.s.e.config.ConfigurationHelper - CacheDecoratorFactory not configured for defaultCache. Skipping for &#39;books&#39;. <br /><br />Finally, as i thought i must have some kind of proxy of my Service class, but i have my own implementation. Is it ok? It works different way?<br />Any ideas?<br />Timhttps://www.blogger.com/profile/17275906006401076040[email protected]tag:blogger.com,1999:blog-3237724005744642470.post-27831364739594767262012-09-12T12:48:06.749+01:002012-09-12T12:48:06.749+01:00Christian You&#39;re quite right, this is somethin...Christian<br />You&#39;re quite right, this is something I spotted after I&#39;d published the blog. In my simple example I&#39;m not overriding the equals() method; hence, the code works as it stands because Object.equals() simply performs an &#39;==&#39; comparison. Roger Hugheshttps://www.blogger.com/profile/07042290171112551665[email protected]tag:blogger.com,1999:blog-3237724005744642470.post-40252109985671037652012-09-12T08:12:29.167+01:002012-09-12T08:12:29.167+01:00You need to use assertSame, otherwise the code dep...You need to use assertSame, otherwise the code depends on .equals(Object), which hasn&#39;t been shown. It may have been overridden to compare all properties and then this test would always pass, even if nothing was cached.Christian Schlichtherlehttps://www.blogger.com/profile/05834236027490468214[email protected]