Page 1 of 1

Page Caching - Storing list response on the page

Posted: Mon Aug 12, 2013 12:34 pm
by vipul

Hi , how do i store a page in the cache memory . Onload i need to fire a list service , but when i perform some other query and return to the previous page(where i fired the original list service) , i do not want to refire the same service , but the service should be fired only if the user clicks on refresh.


Page Caching - Storing list response on the page

Posted: Mon Aug 12, 2013 5:21 pm
by maxkatz

You could add some logic not to fire the service again if the page had already loaded and the service loaded the list.


Page Caching - Storing list response on the page

Posted: Wed Aug 14, 2013 7:09 am
by vipul

Hi , the service is written in page load.
I added a variable to local storage to check if the page has already been loaded. But this does not let me use the option to run the service on page load . Please could you give me an example to add the logic. I still want to be able to use the data type mapping feature provided.


Page Caching - Storing list response on the page

Posted: Wed Aug 14, 2013 10:03 am
by Maryna Brodina

Hello! It's better do not use Echo for service http://docs.appery.io/documentation/r.... On service success fill in echo service parameter codeservice_instance_name.requestOptions.echo = JSON.stringify(data);/code
Next time you call service it won't be called, but parameters would be mapped using data from echo parameter. When you need to update it before service call reset echo parameter codeservice_instance_name.requestOptions.echo = '';/code


Page Caching - Storing list response on the page

Posted: Wed Aug 14, 2013 11:37 am
by Asif

hi i created a studentList service .
and in the data tab added an on success event which does the following

studenList.requestOptions.echo = JSON.stringify(data);

I get the following error when i test the application .
Uncaught TypeError: Cannot set property 'echo' of undefined

Please can you let me know where i am going wrong.


Page Caching - Storing list response on the page

Posted: Wed Aug 14, 2013 12:31 pm
by Maryna Brodina

Instead codeservice_instance_name.requestOptions.echo/code use codeservice_instance_name.__requestOptions.echo/code


Page Caching - Storing list response on the page

Posted: Mon Aug 19, 2013 6:27 am
by Asif

It still did not work .. please give me a sample code


Page Caching - Storing list response on the page

Posted: Mon Aug 19, 2013 8:35 am
by Kateryna Grynko

Hi Asif,

Echo mode in a simple form will not help you. In your case, you need a more complex logic. Your application must contain a caching mechanism that controls the lifetime of the cache (it may become out of date) and checking whether requested data corresponds to the existing cache data.

In the context of REST-services, it is not a trivial task.

Before invoking service, you need to check whether there is a service response in localStorage. As well, the answer should be fairly fresh (you have to define yourself the cache lifetime based on your app context), which means that you need to save to localStorage not only the service response, but the date-time of saving and the cache lifetime. It's necessary to take into account the changing parameters of the request. That is, if the query parameters have been changed (for example, value of one of the localStorage variables involved in the request was changed), then you need to make this request and cache its response for the next time.