Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to refresh a model cache when an external resource changes?
How to refresh a model cache when an external resource changes? [message #904820] Wed, 29 August 2012 08:03 Go to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
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 #904982 is a reply to message #904820] Wed, 29 August 2012 14:08 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik Lindberg
Messages: 2500
Registered: July 2009
Senior Member
On 2012-29-08 10:03, Aaron Digulla wrote:
>
> I need to flush the cache when model.config is updated. How can I do that?
>

I do something similar when validation preferences are changed in
Geppetto - I just trigger a new build of everything (in my case anything
could be affected by the change).

Is that what you want to do? Can point you to my code.

- henrik
Re: How to refresh a model cache when an external resource changes? [message #905411 is a reply to message #904982] Thu, 30 August 2012 10:42 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
Registered: July 2009
Location: Switzerland
Senior Member
Henrik Lindberg wrote on Wed, 29 August 2012 16:08
I do something similar when validation preferences are changed in
Geppetto - I just trigger a new build of everything (in my case anything
could be affected by the change).

Is that what you want to do? Can point you to my code.
- henrik


No, sorry.

What I need is add more URLs to check for changes to res.getCache().get() so it calles the inner get() method when one of them changes.
Re: How to refresh a model cache when an external resource changes? [message #905428 is a reply to message #904820] Thu, 30 August 2012 11:13 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2903
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 16:23 Go to previous messageGo to next message
Aaron Digulla is currently offline Aaron Digulla
Messages: 258
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:13
Hi 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 Smile

How does Xtend know that a dependency has changed?

Regards,

A. Digulla

[Updated on: Mon, 03 December 2012 16:24]

Report message to a moderator

Re: How to refresh a model cache when an external resource changes? [message #1047562 is a reply to message #904982] Tue, 23 April 2013 11:36 Go to previous message
Chris Ainsley is currently offline Chris Ainsley
Messages: 74
Registered: March 2010
Location: UK
Member

Hi Henrik,

It would be helpful if you could point to the place in your code where you manually trigger a new build of everything.

Thanks again,

Chris

Henrik Lindberg wrote on Wed, 29 August 2012 23:08
On 2012-29-08 10:03, Aaron Digulla wrote:
>
> I need to flush the cache when model.config is updated. How can I do that?
>

I do something similar when validation preferences are changed in
Geppetto - I just trigger a new build of everything (in my case anything
could be affected by the change).

Is that what you want to do? Can point you to my code.

- henrik

Previous Topic:Add/ modify preference page
Next Topic:Triggering a re-link
Goto Forum:
  


Current Time: Thu Oct 23 06:04:21 GMT 2014

Powered by FUDForum. Page generated in 0.02836 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software