sparna-git / Sparnatural

Sparnatural : visual knowledge graph explorer with SPARQL, in the browser, configurable with SHACL
http://sparnatural.eu
GNU Lesser General Public License v3.0
225 stars 41 forks source link

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

Open tfrancart opened 4 years ago

antoine37120 commented 3 years ago

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

antoine37120 commented 3 years ago

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 commented 3 years ago

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

tfrancart commented 3 years ago

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

antoine37120 commented 3 years ago

@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) ;
tfrancart commented 2 years ago

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.