This code produces the expected behavior:
#import <Foundation/Foundation.h>
@interface A : NSObject
+ (NSCache *)itemCache;
@end
@implementation A
+ (NSCache *)itemCache {
static NSCache *itemCache;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
itemCache = [[NSCache alloc] init];
});
return itemCache;
}
@end
@interface B : A
@end
@implementation B
@end
@interface C : A
@end
@implementation C
@end
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSLog(@"%@ %@ %@", [A itemCache], [B itemCache], [C itemCache]);
}
return 0;
}
logs:
<NSCache: 0x1002000e0> <NSCache: 0x1002000e0> <NSCache: 0x1002000e0>
your issue must be else-where.