Cachefactory

Hi

I am new to IONIC Framework.I am developing an App using ionic.I have a list of items populated on firstpage based on values return from jsonp (http.jsonp(url)).when i click on one item it goes to detail view as normal.

I want to store these values in cache because every time when i go back to list it always calls jsonp request and loads the data and it takes time.Can anyone please try to help me to fix this issue.I have gone through cache factory but i dont know how to use it…

Thanks a lot

Hey ashique,

it sounds like someone needs a service!
https://docs.angularjs.org/guide/services

Create a service for your API calls and store the repsonse objects in a variable in your service.
You can include your service in your controller and get access to the response everytime you want ;).

Creating a factory or service is very similar to creating a controller. (instead of .controller(‘name’, …) use .service(‘name’, …) .
Add functions and variables.
Include your service like you include ionic-directives or anuglarjs services and you can call myService.functionName() or use myService.data.

Greetz, bengtler

1 Like

Okay i do not use $cacheFactory…
I store the values only on an object or a variable in the service. But it seems be something like cacheFactory.

I think you can use cacheFactory in service to set/write the data and in the controller to get/read the data.

Hi Bengtler

Finally It worked fine now with CacheFactory.Thanks for your reply.

Ash