![]() ![]() ![]() If you don't, you will have to rely on eviction. If you have a final step where you know you won't need the entry anymore, just remove it there. Use it and finally remove it to save memory. In your case, you will want to load the entry once. It means that an expired entry will stay in the cache until you try to access it. If it is, it will return null and remove the entry from the cache. When you get an entry, Ehcache first looks if the entry is expired. For instance, you want to keep an entry 1 hour before refreshing the entry with the latest one in the database. Ehcache does a sampling over a set of entries and kicks out the entry that wasn't accessed for the longest time in the sample.Įxpiration means that a given entry will be considered stale at some point. There are multiple definitions for oldest. When this is reached, the cache will evict the "oldest" entry to add a new one. It evicts and expires.Įviction means that you set some maximum size to the cache. Then, a cache does mostly two things on top of a HashMap. So yes, even retrieving once from the cache will make it faster then boing back to the database. So if we had a quite small cache (because I want to keep heap memory under close control) I would expect the first few folders to be processed to have their songs added to the cache, then as they complete songs from new folders would take their place in the cache.Īs a rule of thumb does 10 retrievals versus 1-4 writes makes sense of using 2nd level cache, or is only useful if the ratio is more like 100:1? So there are no particular song ids that are retrieved 1000s of times, but every song is typically written to between 1 and 4 times and retrieves 10 times. So when a particular task is actually run on an Executor the first thing it does is retrieve the songs for those ids. My songs are processed folder by folder and go through a number of stages (on different Executors), when they are queued on the next Executor we just pass the song ids as parameters otherwise, it would use a lot of heap memory storing the Song objects themselves. But subsequent retrieval of the song from Ehcache will require less resource then retrieving it from database. Once the songs have been processed then those songs are of no interest (unless the user runs Undo)Īs I understand it if I enable 2nd level cache (for my song class) then the initial write of the song to cache will use more cpu then if just writing to database, and additional modifications to the song object will also require more cpu resource. This is for an application that processes music files (and it uses Hibernate so it can scale with more data, i.e it can process 100,000 songs with little more memory than 1000 songs. I am currently using Hibernate without 2nd level cache. When does the CPU benefit of having an object added to Hibernate 2nd level object cache outweigh the initial hit.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |