vipul
Posts: 0
Joined: Wed Jul 31, 2013 8:59 am

Page Caching - Storing list response on the page

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Page Caching - Storing list response on the page

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

vipul
Posts: 0
Joined: Wed Jul 31, 2013 8:59 am

Page Caching - Storing list response on the page

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.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Page Caching - Storing list response on the page

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

Asif
Posts: 0
Joined: Tue Aug 13, 2013 12:56 pm

Page Caching - Storing list response on the page

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.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Page Caching - Storing list response on the page

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

Asif
Posts: 0
Joined: Tue Aug 13, 2013 12:56 pm

Page Caching - Storing list response on the page

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Page Caching - Storing list response on the page

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.

Return to “Issues”