| How to refresh a model cache when an external resource changes? [message #904820] |
Wed, 29 August 2012 04:03  |
Aaron Digulla Messages: 234 Registered: July 2009 Location: Switzerland |
Senior Member |
|
|
I keep a cache of expensive values in my code which is attached to the model:
public static ValidationCache getValidationCache( EObject obj ) {
final XtextResource res = (XtextResource) obj.eResource();
final I18nDomainModel model = getModel( obj );
return res.getCache().get( ValidationCache.class.getName(), res, new Provider<ValidationCache>() {
@Override
public ValidationCache get() {
// log.debug( "New cache for " + res );
return new ValidationCache( model );
}
} );
}
This works pretty well. Now I have an external resource with some options. For the sake of the question, let's say I have this:
model.i18n <-- Xtext resource
model.config <-- Additional resource
I need to flush the cache when model.config is updated. How can I do that?
Regards,
A. Digulla
|
|
|
|
|
| Re: How to refresh a model cache when an external resource changes? [message #905428 is a reply to message #904820] |
Thu, 30 August 2012 07:13   |
Sebastian Zarnekow Messages: 2788 Registered: July 2009 |
Senior Member |
|
|
Hi Aaron,
please make sure that IResourceDescription.Manager returns true on the
#isAffected query as soon as the dependent resource changes
significantly for your caching mechanism.
If that does not work for you for some reason, you'll most likely have
to implement that in your ValidationCache. Btw: Which sort of
information do you store in that cache. Is that something that should be
user data in the resource description itself?
Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 29.08.12 10:03, schrieb Aaron Digulla:
> I keep a cache of expensive values in my code which is attached to the
> model:
>
>
> public static ValidationCache getValidationCache( EObject obj ) {
> final XtextResource res = (XtextResource) obj.eResource();
> final I18nDomainModel model = getModel( obj );
> return res.getCache().get( ValidationCache.class.getName(), res,
> new Provider<ValidationCache>() {
> @Override
> public ValidationCache get() {
> // log.debug( "New cache for " + res );
> return new ValidationCache( model );
> }
> } );
> }
>
>
> This works pretty well. Now I have an external resource with some
> options. For the sake of the question, let's say I have this:
>
>
> model.i18n <-- Xtext resource
> model.config <-- Additional resource
>
>
> I need to flush the cache when model.config is updated. How can I do that?
>
> Regards,
>
> A. Digulla
|
|
|
| Re: How to refresh a model cache when an external resource changes? [message #988905 is a reply to message #905428] |
Mon, 03 December 2012 11:23   |
Aaron Digulla Messages: 234 Registered: July 2009 Location: Switzerland |
Senior Member |
|
|
Sebastian Zarnekow wrote on Thu, 30 August 2012 13:13
please make sure that IResourceDescription.Manager returns true on the
#isAffected query as soon as the dependent resource changes
significantly for your caching mechanism.
This looks promising but my dependency isn't a resource. Imagine my problem to be the same as Xtend and Java: When Xtend imports Java code and I change the *Java* code, the validation/code generation of *Xtend* is triggered.
I need the same thing.
Sebastian Zarnekow wrote on Thu, 30 August 2012 13:13Hi Aaron,
If that does not work for you for some reason, you'll most likely have
to implement that in your ValidationCache. Btw: Which sort of
information do you store in that cache. Is that something that should be
user data in the resource description itself?
The problem isn't where to store this information; my problem is solely how to make sure the cache is never stale.
What I have: A list of URIs to imported files. I can probably get lastModified for each of URI. I can't load the URIs into XtextResource or EMF ResourceSets; there is no handler for those types.
What I need is code that checks that lastModified is still the same as the one which I've cached and then return the cached copy. If lastModified has changed, then I need to purge this element from the cache and build a new one.
I think hooking into the delta build process of Eclipse is promising but I'd rather not reinvent the wheel 
How does Xtend know that a dependency has changed?
Regards,
A. Digulla
[Updated on: Mon, 03 December 2012 11:24] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.13796 seconds