1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
//
// Lynkeos
// $Id$
//
// Created by Jean-Etienne LAMIAUD on Fri Mar 14 2008.
// Copyright (c) 2008-2018. Jean-Etienne LAMIAUD
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
/*!
* @header
* @abstract Class used to cache any kind of object
*/
#ifndef __MYOBJECTCACHE_H
#define __MYOBJECTCACHE_H
#import <Foundation/Foundation.h>
//! Policy for refreshing the cache (ie: putting an object on top of the cache)
enum
{
ReadRefresh = 0x0001,
WriteRefresh = 0x0002
};
//! Cache strategy for maximum capacity
typedef enum
{
CacheNumberOfObjects = 0,
CacheMemorySize
} CacheCapacityStrategy_t;
/*!
* @abstract This class caches any kind of object
*/
@interface LynkeosObjectCache : NSObject
{
@private
CacheCapacityStrategy_t _capacityStrategy; //!< Cache capacity strategy
NSMutableDictionary *_cacheDict; //!< Objects stored by keys
NSMutableArray *_keyAge; //!< Keys stored by age
u_long _capacity; //!< Maximum number or size
u_long _size; //!< Current size
u_short _policy; //!< Refresh policy
}
/*!
* @abstract Common cache for movie classes
* @param cache The new movie cache
* @result The movie class common cache
*/
+ (void) setMovieCache:(LynkeosObjectCache*)cache ;
/*!
* @abstract Common cache for processing images
* @param cache The new image processing cache
* @result The image processing common cache
*/
+ (void) setImageProcessingCache:(LynkeosObjectCache*)cache ;
/*!
* @abstract Common cache for movie classes
* @result The movie class common cache
*/
+ (LynkeosObjectCache*) movieCache ;
/*!
* @abstract Common cache for processing images
* @result The image processing common cache
*/
+ (LynkeosObjectCache*) imageProcessingCache ;
/*!
* @abstract Initializer
* @discussion When first added to the cache, objects are always at the top,
* whatever the policy
* @param strategy Caching strategy (memory size or number of objects)
* @param capacity The maximum number of objects, or maximum memory in the cache
* @param policy The refresh policy of the cache
* @result The initialized cache object
*/
- (id) initWithStrategy:(CacheCapacityStrategy_t)strategy
capacity:(u_long)capacity policy:(u_short)policy ;
/*!
* @abstract Put an object in the cache
* @discussion The object is retained by the cache and released when deleted
* from it
* @param obj The object to add to the cache
* @param key The key to identify this object
*/
- (void) setObject:(NSObject*)obj forKey:(id)key ;
/*!
* @abstract Retrieve an object from the cache
* @param key the key for this object
* @result The object it it was found in the cache, nil otherwise
*/
- (NSObject*) getObjectForKey:(id)key ;
/*!
* @abstract Remove an object from the cache
* @param key the key for this object
*/
- (void) removeObjectForKey:(id)key ;
/*!
* @abstract Adapt the cache to a new size
* @param capacity The new size
*/
- (void) setCapacity:(u_long)capacity ;
@end
#endif
|