TumblrArchive / TMCache

Fast parallel object cache for iOS and OS X.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not saving into disc cache, stores only in memory.

KanybekMomukeyev opened this issue · comments

Hi, i did like this

[[TMCache sharedCache] setObject:Image
                                  forKey:@"ImageKey"
                                   block:^(TMCache *cache, NSString *key, UIImage *storedImage){}];

But, when i remove application from memory,
and re run application

[[TMCache sharedCache] objectForKey:@"ImageKey" ^(TMCache *cache, NSString *key, UIImage *storedImage) {
NSLog(@"%@",storedImage)
}];

returns Null.

I changed all properties: Max limit of bytes

Solve the problem:

UIImage *image = [[TMCache sharedCache] objectForKey:@"ImageKey"];

Each of the basic cache operations has two manifestations, a synchronous method and an asynchronous method. objectForKey: will return the object after some time, objectForKey:block: will return void immediately and you can access the object within the passed block (once it becomes available). If the block is empty nothing will happen and the object lookup is wasted.

For methods where the block is optional, like setObject:forKey:block:, you can safely pass nil for the block argument instead of writing out the whole type. The operation still completes asynchronously.

[[TMCache sharedCache] setObject:Image forKey:@"ImageKey" block:nil];

[[TMCache sharedCache] objectForKey:@"ImageKey"
    block:^(TMCache *cache, NSString *key, UIImage *storedImage) {
        NSLog(@"your object is here %@", storedImage);
}]; // returns immediately

Thanks JSTN,
yes, i understand that (synchronous, asynchronous).
I editted above issue.