Caching on a DOM Converter

Hi there

I'm using the XML DOM on my plugin. I have a Converter for some kind of references, and I'd like to cache some things (like some properties files I've found after doing some calculations on my Converter) so I don't do the work over and over again for all the references on my XML file.

What's the best approach in this case? Does IDEA only create one class of my Converter? If that's the case, I can store a Map on it with the stuff I want.

Thank you in advance!


This is a good question! :)

I think this is maybe what SEM is for? JAM and SEM are briefly mentioned on an article here

There does seem to be some code within the struts2 plugin that does some sort of caching with SEM; But i'm not sure of the details :(




SEM seems like a very good start, and even if not for this, I'm sure I'll find uses for it :). Unless anyone from JetBrains says otherwise, I think I can store the things I want to cache against my XmlFile or root tag. That way I could always find it!

Thank you!


If you profiled your code and _really_ need caching, then you can use CachedValue and store it on XmlFile (if it's file dependent) or even on a "higher level" (Module, Project). Pay uttermost attention on the "depending" values for proper cache invalidation.


Well, I haven't done any profiling yet, but the "algorithm" is something along the lines of:

1. Find .properties files linked to this XML flie (<properties file=""> elements)
2. Find the real PropertyFile for each of those
3. For each property on the XML file (<element prop=""/>), resolve it and provide a reference.

I want to cache the first two steps, as it's obviously going to be a waste of time calculating those steps every time I find a property (there are a few dozen per XML file).


Use and, they should be fast enough without caching in most cases.


Yeah, I'm using those already for my Folding provider (same stuff there, folding property references to show the real values). On a related note, is there any way of doing that folding "automatically"? Right now, I'm using a folding provider and manually finding each XmlAttribute and providing the reference, but that feels clumsy.

Anyway, I'll profile my converter tomorrow to see what happens.

Thanks a lot, this is awesome support :D!


I don't know of any better way to provide folding. You could use DomElementVisitor to write "higher-level" code for visiting necessary attributes, though.


Please sign in to leave a comment.