Latest 0.1
License MIT
Platforms ios 6.0, requires ARC

Objective-C implementation of in-memory Least Recently Used(LRU) cache.


Create subclass of LruCache. For example: an ImageCache class to cache UIImage objects.

#import "LruCache.h"

@interface ImageCache : LruCache


Override sizeOf: method to provide customized size of stored object.

@implementation ImageCache

- (NSInteger)sizeOf:(NSString *)key value:(id)value
    UIImage *img = (UIImage *)value;
    CGSize size = img.size;
    return (NSInteger)ceil(size.height * size.width * img.scale * 4);


Instantiate ImageCache and use put: and get: method to store and retrieve objects.

ImageCache *imageCache = [[ImageCache alloc] initWithMaxSize:1024 * 1024 * 30]; // 30MB image cache.

NSString *key = @"img.png";
UIImage *img = [UIImage imageNamed:@"img.png"];
[imageCache put:key value:img];
UIImage *img = [imageCache get:key];


Install using CocoaPods:

pod 'LruCache'


LruCache is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "LruCache",
    "version": "0.1",
    "summary": "Objective-C implementation of Least Recently Used(LRU) cache.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "robinz": "[email protected]"
    "platforms": {
        "ios": "6.0"
    "source": {
        "git": "",
        "tag": "0.1"
    "source_files": "LruCache/LruCache.{h,m}",
    "requires_arc": true

Pin It on Pinterest

Share This