EGOCache cache framework

Source: Internet
Author: User

EGOCache cache framework



EGOCacheIs a lightweight cache framework. It is easy to use. In my current project, I used EGOCache to cache the downloaded photos and strings.

Someone may ask, do you still need to use EGOCache to cache photos? Are AFNetworking and SDWebImage already available?

Yes, but AFNetworking and SDWebImage are http. My project uses socket, so I chose EGOCache for caching. It seems that EGOCache is quite powerful.

EGOCache Introduction
EGOCache is a simple, thread-safe key value cache store. It has native support for NSString, UI/NSImage, and NSData, but can store anything that implements <NSCoding>. All cached items expire after the timeout, which by default, is one day.

EGOCache is a simple, thread-safe key-value-based Cache framework. It supports native NSString, UI/NSImage, and NSData, and supports storing any classes that implement the Protocol, you can set the cache expiration time. The default value is 1 day.

EGOCache has only one class, EGOCache. h and EGOCache. m files. The usage is also easy to grasp. Take a closer look at the EGOCache. h method and you will soon be able to get started.

EGOCache only provides disk cache, but does not provide memory cache. In addition, the following methods are provided to clear the cache:

- (void)clearCache;

EGOCache also provides methods to determine whether the cache exists:

- (BOOL)hasCacheForKey:(NSString* __nonnull)key;
Join the project directly through Cocoapods

Add the following line directly to the Podfile of your project:

pod 'EGOCache'

Then execute:

$ pod update
Use EGOCache to cache NSString

Storage:

NSString * saveString = @ "Save Me"; [[EGOCache globalCache] setString: saveString forKey: [NSString stringWithFormat: @ "EGOImageLoader-% lu", (unsigned long) [saveString hash] withTimeoutInterval: 24*60*60];

Read:

NSString *getSaveString = [[EGOCache globalCache] stringForKey:[NSString stringWithFormat:@"EGOImageLoader-%lu", (unsigned long)[@"SaveString" hash]]];

Is it similar to NSDictionary? Indeed, we mentioned earlier that EGOCache is a key-value-based Cache framework.

Cache UIImage with EGOCache

Storage:

 UIImage *saveImage = [UIImage imageNamed:@"iOSDevTip"];[[EGOCache globalCache] setImage:saveImage forKey:[NSString stringWithFormat:@"EGOImageLoader-%lu", (unsigned long)[@"SaveImage" hash]] withTimeoutInterval:24*60*60];

Read:

UIImage *getSaveImage = [[EGOCache globalCache] imageForKey:[NSString stringWithFormat:@"EGOImageLoader-%lu", (unsigned long)[@"SaveImage" hash]]];
Use EGOCache to cache NSData

Storage:

NSData *saveData = [NSData data];[[EGOCache globalCache] setData:saveData forKey:[NSString stringWithFormat:@"EGOImageLoader-%lu", (unsigned long)[@"SaveData" hash]] withTimeoutInterval:24*60*60];

Read:

UIImage *getSaveData = [[EGOCache globalCache] dataForKey:[NSString stringWithFormat:@"EGOImageLoader-%lu", (unsigned long)[@"SaveData" hash]]];
Download EGOCache source code

EGOCache

Author Li Gang is the webmaster of the online website (www.superqq.com), author of Baidu baijia Column
IOS engineers are not well-known self-media and the public account is iOS developer: iOSDevTip Operator


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.