Best practices for Expiring/refreshing dataSource data

4 posts, 0 answers
  1. Marlon
    Marlon avatar
    16 posts
    Member since:
    Jul 2013

    Posted 23 Jul 2013 Link to this post

    I'm working on a mobile app were some of the data requests will be cached in localStorage on the device. Depending on the data, I'd like to assign a timeout value for it that would flush the existing value and make new network request. I'm assuming I'll need to set timestamps into localStorage, check them when the data is requested and if its expired, execute a read() on the object to refresh the data.

    Would that be a plausible solution or are there features of the framework that I've overlooked for this type of thing?

  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 25 Jul 2013 Link to this post

    Hello Marlon,

    Basically what the dataSource provides you when you want to refresh the records with fresh copies from the server is to use the dataSource.read() method.

    Please notice that refreshing just a single record from the server is not possible - when read is performed all the records for the given page/filter/sort descriptors will be fetched from the server.

    Kind Regards,
    Petur Subev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Marlon
    Marlon avatar
    16 posts
    Member since:
    Jul 2013

    Posted 25 Jul 2013 Link to this post

    Hi Petur,

    Thank you for the response.  I may not have phrased my question correctly...the issue that I'm having is that I'm building a mobile app where some of the data needs to persist...in case the app is closed completely and then opened while the device is offline, we want to keep some pieces of data. 

    In the prototype I'm working on, I've wrapped the dataSource in a deferred object that checks against the localStorage, if its expired, .read() is called.

    I feel like there's an easier way to accomplish this but I just wanted to know if  there is a better solution. I like the binding functionality wrapped in dataSource but I need an extra layer to manage how/when new data is requested.
    var listNotifications = function(){
            var deferred = $.Deferred();
     
            var bool = utils.dataStoreIsValid(constants.listNotifications);
            if(bool) {
                var payload = utils.getStorage(constants.listNotifications);
                       notificationsDataSource.data(payload)
                       deferred.resolve(payload);
            } else {
                notificationsDataSource.bind('change', function(){
                    deferred.resolve(notificationsDataSource.data());
                });
                notificationsDataSource.read();
            }
            return deferred.promise();
        }
  5. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 29 Jul 2013 Link to this post

    Hello Marion,

    I am sorry I misunderstood the case.

    Generally speaking the idea that you shared sounds just fine - if there is no items in the localStorage use the dataSource.read to fetch the records from the server, otherwise load the items from the localStorage with the dataSource.data method.

    Kind Regards,
    Petur Subev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
Kendo UI is VS 2017 Ready