From 373966f78f8d00e3506f6caf4a3d30114c785131 Mon Sep 17 00:00:00 2001 From: Aodh O Lionaird Date: Thu, 25 Sep 2025 14:31:33 +0200 Subject: [PATCH] Expose update time --- Sources/SPTPersistentCache.m | 3 ++- Sources/SPTPersistentCacheRecord+Private.h | 5 +++++ Sources/SPTPersistentCacheRecord.m | 12 +++++++++++- .../SPTPersistentCache/SPTPersistentCacheRecord.h | 4 ++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Sources/SPTPersistentCache.m b/Sources/SPTPersistentCache.m index 3dc480c..1a7a897 100644 --- a/Sources/SPTPersistentCache.m +++ b/Sources/SPTPersistentCache.m @@ -589,7 +589,8 @@ - (void)loadDataForKeySync:(NSString *)key SPTPersistentCacheRecord *record = [[SPTPersistentCacheRecord alloc] initWithData:payload key:key refCount:refCount - ttl:ttl]; + ttl:ttl + updateTime:localHeader.updateTimeSec]; SPTPersistentCacheResponse *response = [[SPTPersistentCacheResponse alloc] initWithResult:SPTPersistentCacheResponseCodeOperationSucceeded error:nil diff --git a/Sources/SPTPersistentCacheRecord+Private.h b/Sources/SPTPersistentCacheRecord+Private.h index a38c7d9..cedbd25 100644 --- a/Sources/SPTPersistentCacheRecord+Private.h +++ b/Sources/SPTPersistentCacheRecord+Private.h @@ -27,4 +27,9 @@ refCount:(NSUInteger)refCount ttl:(NSUInteger)ttl; +- (instancetype)initWithData:(NSData *)data + key:(NSString *)key + refCount:(NSUInteger)refCount + ttl:(NSUInteger)ttl + updateTime:(NSUInteger)updateTime; @end diff --git a/Sources/SPTPersistentCacheRecord.m b/Sources/SPTPersistentCacheRecord.m index 7d14ea5..c046047 100644 --- a/Sources/SPTPersistentCacheRecord.m +++ b/Sources/SPTPersistentCacheRecord.m @@ -29,6 +29,15 @@ - (instancetype)initWithData:(NSData *)data key:(NSString *)key refCount:(NSUInteger)refCount ttl:(NSUInteger)ttl +{ + return [self initWithData:data key:key refCount:refCount ttl:ttl updateTime:0]; +} + +- (instancetype)initWithData:(NSData *)data + key:(NSString *)key + refCount:(NSUInteger)refCount + ttl:(NSUInteger)ttl + updateTime:(NSUInteger)updateTime { self = [super init]; if (self) { @@ -36,6 +45,7 @@ - (instancetype)initWithData:(NSData *)data _ttl = ttl; _key = [key copy]; _data = data; + _updateTime = updateTime; } return self; } @@ -49,7 +59,7 @@ - (NSString *)description - (NSString *)debugDescription { - return SPTPersistentCacheObjectDescription(self, self.key, @"key", @(self.ttl), @"ttl", @(self.refCount), @"ref-count"); + return SPTPersistentCacheObjectDescription(self, self.key, @"key", @(self.ttl), @"ttl", @(self.updateTime), @"updated", @(self.refCount), @"ref-count"); } @end diff --git a/include/SPTPersistentCache/SPTPersistentCacheRecord.h b/include/SPTPersistentCache/SPTPersistentCacheRecord.h index bf535a9..8f421b7 100644 --- a/include/SPTPersistentCache/SPTPersistentCacheRecord.h +++ b/include/SPTPersistentCache/SPTPersistentCacheRecord.h @@ -48,6 +48,10 @@ NS_ASSUME_NONNULL_BEGIN Data that was initially passed into storeData:... */ @property (nonatomic, strong, readonly) NSData *data; +/* + * Update time of the record (when it was last stored or accessed) + */ +@property (nonatomic, assign, readonly) NSUInteger updateTime; @end