Sparnatural icon indicating copy to clipboard operation
Sparnatural copied to clipboard

Cache list of values between 2 selections (to avoid fetching data twice)

Open tfrancart opened this issue 5 years ago • 6 comments

tfrancart avatar May 02 '20 21:05 tfrancart

Last commit is on issue-173 branch....

antoine37120 avatar Sep 17 '21 09:09 antoine37120

LocalCacheData Class can be a singleton Class, Here is a true exemple of this partern on js :

var mySingleton = (function () {

  // Instance stores a reference to the Singleton
  var instance;

  function init() {

    // Singleton

    // Private methods and variables
    function privateMethod(){
        console.log( "I am private" );
    }

    var privateVariable = "Im also private";

    return {

      // Public methods and variables
      publicMethod: function () {
        console.log( "The public can see me!" );
      },

      publicProperty: "I am also public"
    };

  };

  return {

    // Get the Singleton instance if one exists
    // or create one if it doesn't
    getInstance: function () {

      if ( !instance ) {
        instance = init();
      }

      return instance;
    }

  };

})();

// Usage:

var singleA = mySingleton.getInstance();
var singleB = mySingleton.getInstance();
console.log( singleA === singleB ); // true

This, will be used if we can use an alternative if browser don't support localStorage. We can save last loading time on variable array in singleton class. Value is the same for all class instance. The array key can be uri used for fetch, is the same for localSorage. For user, no différence for performances, this change just the mecanisme for saving last loading date for a resource and cache is always used for stroring data.

antoine37120 avatar Sep 17 '21 12:09 antoine37120

@tfrancart You can check this (1 minute for browser caching ttl)

antoine37120 avatar Sep 20 '21 08:09 antoine37120

Can you set ttl to 24 hours ? Thanks

Le lun. 20 sept. 2021 à 10:04, antoine37120 @.***> a écrit :

@tfrancart https://github.com/tfrancart You can check this (1 minute for browser caching ttl)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sparna-git/Sparnatural/issues/157#issuecomment-922709283, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAU2H4LWBPZNYWQ3UJX5LR3UC3TH3ANCNFSM4MX2ZJQQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

--

Thomas Francart -* SPARNA* Web de données | Architecture de l'information | Accès aux connaissances blog : blog.sparna.fr, site : sparna.fr, linkedin : fr.linkedin.com/in/thomasfrancart tel : +33 (0)6.71.11.25.97, skype : francartthomas

tfrancart avatar Sep 20 '21 08:09 tfrancart

@tfrancart Ok, you can check this with custom local storage class (LocalDataStorage). This class can be used in global scripst to store data shared in one loading page execution. This class use singleton patern for have the same instance for all calls. To use this class (set value):

var datastorage = LocalDataStorage.getInstance();
datastorage.set(key, value) ;

And anywhere in script (get value) :

var datastorage = LocalDataStorage.getInstance();
var neededValue datastorage.get(key) ;

antoine37120 avatar Sep 28 '21 08:09 antoine37120

The current implementation works only if the server explicitely allowed the client to cache. A server-side cache would be preferable. 2 URLs could be defined on the server : one with cache, one without cache, and the Sparnatural config could use 2 endpoint URLs, one for queries for lists, the other for all the rest.

tfrancart avatar Dec 03 '21 12:12 tfrancart