Disadvantages of caching in converted XML memory?

I am writing a web application that constantly extracts XML components from a database and then converts them to XHTML using XSLT. Some of these conversions happen often (for example, the sidebar navigation component goes beyond the same XML and performs the same XSL transform on every page with this sidebar), so I started implementing some caching to speed things up.

In my current solution, before each component tries to perform the conversion, the component checks the static CacheManager object to see if a cached version of the converted XML exists. If so, the component outputs this. If not, the component performs the conversion and then saves the converted XML with a CacheManager object.

The CacheManager object stores the storage in the memory of the cached converted XML (more precisely, in the Dictionary ). In my local development environment, this works great, but I guess it might not be a very scalable solution.

What are the potential failures in storing this data in memory? Do I need to put the amount of data that I can store in such a data structure in memory? Should I use a different data store for this type of caching?

+4
source share
3 answers

The obvious drawback would be, in your opinion, the potentially high level of memory usage by your cache. You may want to implement a system in which rarely used items "expire" from the cache when memory pressure increases. Microsoft's Caching Application Block implements almost everything you need right out of the box.

Another potential (albeit unlikely) problem that you might run into is cache digging costs to find what you need. At some point, it might be faster to just go ahead and generate what you need, rather than view the cache. We came across this with at least one exact scenario related to very large caches and very cheap operations. This is unlikely, but it can happen.

+4
source

You should definitely look for a common chache implementation. I do not do C #, so I do not know any solutions in your language. In Java, I would recommend EHCache.

Caching is a lot more complicated than it sounds. That is why it is probably a good idea to rely on the work done by others. Some problem that you will encounter at some point is concurrency, cache invalidation, lifetime, cache lock, cache management (statistics, clearing caches, ...), disk overflow, distributed caching, ...

Cache monitoring is a must. You need to make sure that the caching strategy that you put in place actually does something good (cache hits / cache misses, percentage of cache used) ... You should probably split your cache in several regions in order to have the ability to better control usage cache.

As a side note, while you are caching your XML after conversion, you should probably keep its String representation (and not the object tree). This is the smaller conversion that needs to be done after the cache, since you are probably outputting it as a String. And there is a good chance that the String representation will take up less space (but, as always, measure it, don't forget my word).

+1
source

You can perform caching, but just save the reference values ​​(uri) in the dictionary and save the actual converted XML to disk. Most likely, it will be faster than extracting values ​​from the database and re-converting, slower than storing all of this in memory, but the problem is that in the first place you need to have all this cached data. It may also allow converted XML documents to survive through recycle / reset, but you will have to rebuild the dictionary, and you will also need to think about β€œexpiring” documents that need to be removed from the disk cache.

Just an idea ..

+1
source

All Articles