iOS data caching problem for iOS development

Source: Internet
Author: User
Tags delete cache

In order to save traffic, but also for a better user experience, many applications now use the local caching mechanism so I looked up the relevant data from the Internet, and found that there are generally two ways. One is to write their own cache processing, one is the use of asihttprequest in the Asidownloadcache.

Here I mainly introduce the first self-study write cache processing mode.

1. The main idea is that the first time there is a network load data to write data into the sandbox, and then log on to the network status to judge, if no network to use the sandbox data, network on the request API to obtain data.


Write Data
Nsarray *arr = Nssearchpathfordirectoriesindomains (Nsdocumentdirectory,nsalldomainsmask, YES);
Get sandbox path
Nsstring*path = [arr =objectatindex:0];
NSSTRING*PSTR = [path=stringbyappendingstring:@ "/data.txt"];

NSData *data1=nsdata DATAWITHCONTENTSOFFILE:PSTR];
Get Sandbox data
Nsarray*array=[nskeyedunarchiver Unarchiveobjectwithdata:data1];

But the way to note this is that there are more and more cached data, so the basic app has a way to delete the cache in the personal settings.

Delete Cache
Nsfilemanager * FileManager = [[Nsfilemanager alloc]init];
[FileManager Removeitematpath:path Error:nil];

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.