Skip to content

Commit a7ddda5

Browse files
committed
Expose update time
1 parent 697e464 commit a7ddda5

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Sources/SPTPersistentCache.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,8 @@ - (void)loadDataForKeySync:(NSString *)key
582582
SPTPersistentCacheRecord *record = [[SPTPersistentCacheRecord alloc] initWithData:payload
583583
key:key
584584
refCount:refCount
585-
ttl:ttl];
585+
ttl:ttl
586+
updateTime:localHeader.updateTimeSec];
586587

587588
SPTPersistentCacheResponse *response = [[SPTPersistentCacheResponse alloc] initWithResult:SPTPersistentCacheResponseCodeOperationSucceeded
588589
error:nil

Sources/SPTPersistentCacheRecord.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,23 @@ - (instancetype)initWithData:(NSData *)data
2929
key:(NSString *)key
3030
refCount:(NSUInteger)refCount
3131
ttl:(NSUInteger)ttl
32+
{
33+
return [self initWithData:data key:key refCount:refCount ttl:ttl updateTime:0];
34+
}
35+
36+
- (instancetype)initWithData:(NSData *)data
37+
key:(NSString *)key
38+
refCount:(NSUInteger)refCount
39+
ttl:(NSUInteger)ttl
40+
updateTime:(NSTimeInterval)updateTime
3241
{
3342
self = [super init];
3443
if (self) {
3544
_refCount = refCount;
3645
_ttl = ttl;
3746
_key = [key copy];
3847
_data = data;
48+
_updateTime = updateTime;
3949
}
4050
return self;
4151
}
@@ -49,7 +59,7 @@ - (NSString *)description
4959

5060
- (NSString *)debugDescription
5161
{
52-
return SPTPersistentCacheObjectDescription(self, self.key, @"key", @(self.ttl), @"ttl", @(self.refCount), @"ref-count");
62+
return SPTPersistentCacheObjectDescription(self, self.key, @"key", @(self.ttl), @"ttl", @(self.updateTime), @"updated", @(self.refCount), @"ref-count");
5363
}
5464

5565
@end

include/SPTPersistentCache/SPTPersistentCacheRecord.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ NS_ASSUME_NONNULL_BEGIN
4848
Data that was initially passed into storeData:...
4949
*/
5050
@property (nonatomic, strong, readonly) NSData *data;
51+
/*
52+
* Update time of the record (when it was last stored or accessed)
53+
*/
54+
@property (nonatomic, assign, readonly) NSTimeInterval updateTime;
5155

5256
@end
5357

0 commit comments

Comments
 (0)