//
//  MPArrayCache.h
//  MathPad
//
//  Created by Kim Wittenburg on 31.08.14.
//  Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//

#import <Foundation/Foundation.h>

// A wrapper around NSCache to support index-based caches. Indexes are
// automatically adjusted to represent array-like behaviours.
@interface MPArrayCache : NSObject {
    @private
    NSCache *_cache;
}

- (id)init; /* designated initializer */

- (void)cacheObject:(id)object
           forIndex:(NSUInteger)index;
- (id)cachedObjectForIndex:(NSUInteger)index;

- (void)clearCacheAtIndex:(NSUInteger)index
        replacementLength:(NSUInteger)replacementLength;
- (void)clearCacheInRange:(NSRange)range
        replacementLength:(NSUInteger)replacementLength;

- (void)replaceCachedObjectAtIndex:(NSUInteger)index
                       withObjects:(NSArray *)objects;
- (void)replaceCachedObjectsInRange:(NSRange)range
                        withObjects:(NSArray *)objects;

@end
