Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Invalidating cached dataSources

    Hi Isomorphic,

    I would like to ask you about your insights about our idea of how to work with cached dataSources.

    We have dataSource with cachedAllData=true.
    Calling invalidateCache will trigger fetch to server to get fresh data. Then DS will trigger refresh on all its components to make them show fresh data. This we call eager cache invalidation.

    Then we had an idea of lazy cache invalidation.
    Calling invalidateCache will only mark DS as invalid. Then later when we or data-bound component call fetch, DS will fetch fresh data from server depending on his state.

    Lazy approach has advantage that we can call invalidateCache many times, but the server fetch will happen only when it is really needed.
    Disadvantage seems to be, that we have to figure out when the component must ask DS for data (for example MenuButton should always call fetch when the menu gets opened).

    SmartGWT framework seems to be supporting only eager invalidating. Or is there a way how to achieve also lazy invalidating?
    We would be glad if you can give us some advices about this topic.

    Regards,
    Matus

    #2
    Hi matus_b,

    I assume subclassing DataSource with something like this should work, shouldn't it?

    Pseudocode:
    Code:
    @Override
    invalidateCache() {
        this.invalidated=true;
    }
    
    @Override
    fetchData() {
       if (this.invalidated) {
          super.invalidateCache();
          this.invalidated=false;
       }
       super.fetchData();
    }
    Only think I'm not sure about is if this will work without a invalidateCache(DSCallback callback) signature, as I assume invalidateCache() is asynchronous.

    Best regards
    Blama
    Last edited by Blama; 6 Nov 2017, 04:54.

    Comment


      #3
      Hi Blama

      Yes, we were thinking in the same direction.

      I am just curious ... maybe Isomorphic team already considered it or maybe they will foresee some pitfalls with this idea.
      Or maybe they will have in mind some alternative which would be better.

      Comment


        #4
        While there is a cacheMaxAge setting, we don't have any other mechanism to invalidate the cache without triggering a fetch.

        Blama's approach won't work as stated because DS.fetchData() is not an override point. However, if you know which components will fetch against this DataSource, you could set up
        code to invalidate the cache right before you create or configure the component such that it is going to fetch.

        Comment

        Working...
        X