Permalink
Browse files

* Expose cache method to get path of a cache key

* Add userInfo to TTURLRequest
  • Loading branch information...
1 parent 2b142fd commit ff236ef0aa6f9f6b03b73a8562c0c4518c60eb0f @joehewitt joehewitt committed Feb 19, 2009
Showing with 33 additions and 23 deletions.
  1. +0 −5 src/TTBookView.m
  2. +1 −1 src/TTTableViewDataSource.m
  3. +1 −1 src/TTTextEditor.m
  4. +15 −14 src/TTURLCache.m
  5. +7 −1 src/TTURLRequest.m
  6. +6 −1 src/Three20/TTURLCache.h
  7. +3 −0 src/Three20/TTURLRequest.h
View
@@ -814,8 +814,6 @@ - (void)animator {
_pageEdges.right = _pageStartEdges.right + _animateEdges.right * pct;
_pageEdges.top = _pageStartEdges.top + _animateEdges.top * pct;
_pageEdges.bottom = _pageStartEdges.bottom + _animateEdges.bottom * pct;
- //TTLOGEDGES(_pageEdges);
-
[self setNeedsLayout];
if (pct == 1.0) {
@@ -846,7 +844,6 @@ - (void)animator2 {
_pageEdges.right = _pageStartEdges.right + _animateEdges.right * pct;
_pageEdges.top = _pageStartEdges.top + _animateEdges.top * pct;
_pageEdges.bottom = _pageStartEdges.bottom + _animateEdges.bottom * pct;
- //TTLOGEDGES(_pageEdges);
[self setNeedsLayout];
@@ -923,8 +920,6 @@ - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent *)event {
_touchEdges = UIEdgeInsetsZero;
for (UITouch* touch in [event allTouches]) {
if (touch == _touch1 || touch == _touch2) {
- // CGPoint pt = [self touchLocation:touch];
- // TTLOG(@"MOVE %d/%d %f x %f", i, [[event allTouches] count], pt.x, pt.y);
_touchEdges = [self stretchTouchEdges:_touchEdges toPoint:[self touchLocation:touch]];
}
}
@@ -77,7 +77,7 @@ - (BOOL)needsReload {
if (self.loadedTimestamp) {
return -[self.loadedTimestamp timeIntervalSinceNow] > TT_DEFAULT_CACHE_EXPIRATION_AGE;
} else {
- return YES;
+ return NO;
}
}
View
@@ -298,7 +298,7 @@ - (void)setText:(NSString*)text {
_textView.text = text;
}
[self updatePlaceholder];
- [self setNeedsLayout];
+ [self constrainToText];
}
- (void)setPlaceholder:(NSString*)placeholder {
View
@@ -78,9 +78,6 @@ - (void)dealloc {
//////////////////////////////////////////////////////////////////////////////////////////////////
-- (NSString*)getCachePathForKey:(NSString*)key {
- return [_cachePath stringByAppendingPathComponent:key];
-}
- (void)expireImagesFromMemory {
while (_mediaSortedList.count) {
@@ -118,7 +115,7 @@ - (BOOL)isImageMimeType:(NSString*)mimeType {
}
- (NSData*)loadDataFromDisk:(NSString*)url {
- NSString* filePath = [self getCachePathForURL:url];
+ NSString* filePath = [self cachePathForURL:url];
NSFileManager* fm = [NSFileManager defaultManager];
if ([fm fileExistsAtPath:filePath]) {
return [[[NSData alloc] initWithContentsOfFile:filePath] autorelease];
@@ -128,7 +125,7 @@ - (NSData*)loadDataFromDisk:(NSString*)url {
}
- (void)writeDataToDisk:(NSData*)imageData withType:(NSString*)type forKey:(NSString*)key {
- NSString* filePath = [self getCachePathForKey:key];
+ NSString* filePath = [self cachePathForKey:key];
NSFileManager* fm = [NSFileManager defaultManager];
[fm createFileAtPath:filePath contents:imageData attributes:nil];
}
@@ -152,13 +149,17 @@ - (NSString *)keyForURL:(NSString*)url {
];
}
-- (NSString*)getCachePathForURL:(NSString*)url {
+- (NSString*)cachePathForURL:(NSString*)url {
NSString* key = [self keyForURL:url];
- return [self getCachePathForKey:key];
+ return [self cachePathForKey:key];
+}
+
+- (NSString*)cachePathForKey:(NSString*)key {
+ return [_cachePath stringByAppendingPathComponent:key];
}
- (BOOL)hasDataForURL:(NSString*)url {
- NSString* filePath = [self getCachePathForURL:url];
+ NSString* filePath = [self cachePathForURL:url];
NSFileManager* fm = [NSFileManager defaultManager];
return [fm fileExistsAtPath:filePath];
}
@@ -175,7 +176,7 @@ - (NSData*)getDataForURL:(NSString*)url expires:(NSTimeInterval)expirationAge
- (NSData*)getDataForKey:(NSString*)key expires:(NSTimeInterval)expirationAge
timestamp:(NSDate**)timestamp {
- NSString* filePath = [self getCachePathForKey:key];
+ NSString* filePath = [self cachePathForKey:key];
NSFileManager* fm = [NSFileManager defaultManager];
if ([fm fileExistsAtPath:filePath]) {
NSDictionary* attrs = [fm attributesOfItemAtPath:filePath error:nil];
@@ -271,10 +272,10 @@ - (void)moveDataForURL:(NSString*)oldURL toURL:(NSString*)newURL {
[_mediaSortedList addObject:newKey];
[_mediaCache setObject:media forKey:newKey];
}
- NSString* oldPath = [self getCachePathForURL:oldKey];
+ NSString* oldPath = [self cachePathForURL:oldKey];
NSFileManager* fm = [NSFileManager defaultManager];
if ([fm fileExistsAtPath:oldPath]) {
- NSString* newPath = [self getCachePathForURL:newKey];
+ NSString* newPath = [self cachePathForURL:newKey];
[fm moveItemAtPath:oldPath toPath:newPath error:nil];
}
}
@@ -285,7 +286,7 @@ - (void)removeURL:(NSString*)url fromDisk:(BOOL)fromDisk {
[_mediaCache removeObjectForKey:key];
if (fromDisk) {
- NSString* filePath = [self getCachePathForKey:key];
+ NSString* filePath = [self cachePathForKey:key];
NSFileManager* fm = [NSFileManager defaultManager];
if (filePath && [fm fileExistsAtPath:filePath]) {
[fm removeItemAtPath:filePath error:nil];
@@ -294,7 +295,7 @@ - (void)removeURL:(NSString*)url fromDisk:(BOOL)fromDisk {
}
- (void)removeKey:(NSString*)key {
- NSString* filePath = [self getCachePathForKey:key];
+ NSString* filePath = [self cachePathForKey:key];
NSFileManager* fm = [NSFileManager defaultManager];
if (filePath && [fm fileExistsAtPath:filePath]) {
[fm removeItemAtPath:filePath error:nil];
@@ -319,7 +320,7 @@ - (void)invalidateURL:(NSString*)url {
}
- (void)invalidateKey:(NSString*)key {
- NSString* filePath = [self getCachePathForKey:key];
+ NSString* filePath = [self cachePathForKey:key];
NSFileManager* fm = [NSFileManager defaultManager];
if (filePath && [fm fileExistsAtPath:filePath]) {
NSDate* invalidDate = [NSDate dateWithTimeIntervalSinceNow:-_invalidationAge];
View
@@ -13,7 +13,7 @@ @implementation TTURLRequest
@synthesize delegate = _delegate, handler = _handler, handlerDelegate = _handlerDelegate,
url = _url, httpMethod = _httpMethod, httpBody = _httpBody, params = _params,
contentType = _contentType, cachePolicy = _cachePolicy, cacheExpirationAge = _cacheExpirationAge,
- cacheKey = _cacheKey, timestamp = _timestamp, loading = _loading,
+ cacheKey = _cacheKey, timestamp = _timestamp, userInfo = _userInfo, loading = _loading,
shouldHandleCookies = _shouldHandleCookies, shouldConvertToMedia = _shouldConvertToMedia,
responseFromCache = _responseFromCache;
@@ -46,6 +46,9 @@ - (id)init {
_cachePolicy = TTURLRequestCachePolicyAny;
_shouldConvertToMedia = NO;
_cacheExpirationAge = 0;
+ _timestamp = nil;
+ _cacheKey = nil;
+ _userInfo = nil;
_loading = NO;
_shouldHandleCookies = YES;
_shouldConvertToMedia = NO;
@@ -61,6 +64,9 @@ - (void)dealloc {
[_params release];
[_contentType release];
[_handler release];
+ [_timestamp release];
+ [_cacheKey release];
+ [_userInfo release];
[super dealloc];
}
View
@@ -70,7 +70,12 @@
/**
* Gets the path in the cache where a URL may be stored.
*/
-- (NSString*)getCachePathForURL:(NSString*)url;
+- (NSString*)cachePathForURL:(NSString*)url;
+
+/**
+ * Gets the path in the cache where a key may be stored.
+ */
+- (NSString*)cachePathForKey:(NSString*)key;
/**
* Gets the data for a URL from the cache if it exists.
@@ -16,6 +16,7 @@
NSTimeInterval _cacheExpirationAge;
NSString* _cacheKey;
NSDate* _timestamp;
+ id _userInfo;
BOOL _loading;
BOOL _shouldHandleCookies;
BOOL _shouldConvertToMedia;
@@ -60,6 +61,8 @@
@property(nonatomic,retain) NSDate* timestamp;
+@property(nonatomic,retain) id userInfo;
+
@property(nonatomic) BOOL loading;
@property(nonatomic) BOOL shouldHandleCookies;

0 comments on commit ff236ef

Please sign in to comment.