Skip navigation.
 
mlRe: Cache Class review (low priority)
FROM : Chris Hanson
DATE : Sat May 03 04:24:04 2008

On May 2, 2008, at 9:32 AM, Western Botanicals wrote:

> http://expresslanevideo.com/transfer/code/CacheTesterh.txt
> http://expresslanevideo.com/transfer/code/CacheTesterm.txt


You can use Xcode's unit testing functionality -- built atop Sen:te's 
OCUnit framework -- to write tests in a standard fashion, rather than 
creating your own custom test code for everything you do.

I wrote a few posts on my weblog about how to use this in a step-by-
step fashion <http://chanson.livejournal.com/182472.html>.

Also, you appear to have a very Java/C#-like coding style.  It'd be 
better to make your Objective-C code fit the style of other Objective-
C code you're likely to read in code samples, Open Source projects, 
and so on:

1.  Do not indent everything between @implementation and @end.
2.  Instead of +getInstance, the method to return a shared cache 
object should be +sharedCache.
3.  Your -init method should do "self = [super init]" and check for 
nil return.
4.  Your -get:, -put:with: and -removeItem: methods should be more 
descriptively named.  For example, -objectWithID:, -
cacheObject:withID:, and -removeObjectWithID:.
5.  Your -run: method should be more descriptively named, for example -
pruneCache:.
6.  You should have a 2-4 character prefix on your class name, since 
Objective-C doesn't have Java/C#-style namespaces.

Are you really going to be caching arbitrary objects?  Or is this for 
some sort of database front-end application where you have a more 
specific row-snapshot class that's going to be cached?  If so, you 
could leverage that to actually get an ID of the object to cache and 
so on, and rename the class to be something like WBRowCache.

Finally, you're going way, way, WAY overboard trying to make this a 
singleton.  Don't bother with all of the extra work you've gone to -- 
overriding +allocWithZone:, -copyWithZone:, -retain, -release, -
autorelease, -dealloc, -retainCount, and so on -- just create it a 
normal NSObject subclass with normal instance variables that can be 
instantiated by +alloc/-init.  Then, in your application, *just* use 
+sharedCache to get at the cache.  When the time comes that you need 
separate instances for different purposes, you won't have to rip 
anything out, and the work to *ensure* singleton-ness tends to be 
busywork anyway.

  -- Chris

PS - Instead of posting this stuff on your web site as text files, 
give <http://paste.lisp.org/> a try.  It does useful things like 
syntax coloring.  Oh, and use spaces instead of tabs inside your code, 
at least when posting it to the web; most web browsers and editors 
will treat a hard tab in a text file as 8 characters.

Related mailsAuthorDate
mlCache Class review (low priority) Western Botanicals Apr 30, 15:50
mlRe: Cache Class review (low priority) Jean-Daniel Dupas Apr 30, 16:44
mlRe: Cache Class review (low priority) Jens Alfke Apr 30, 17:08
mlRe: Cache Class review (low priority) Western Botanicals May 1, 00:14
mlRe: Cache Class review (low priority) Jens Alfke May 1, 04:30
mlRe: Cache Class review (low priority) Western Botanicals May 2, 01:49
mlRe: Cache Class review (low priority) Jens Alfke May 2, 06:58
mlRe: Cache Class review (low priority) Gregory Weston May 2, 13:37
mlRe: Cache Class review (low priority) Jens Alfke May 2, 17:22
mlRe: Cache Class review (low priority) Western Botanicals May 2, 18:32
mlRe: Cache Class review (low priority) Jens Alfke May 2, 20:03
mlRe: Cache Class review (low priority) Uli Kusterer May 2, 22:29
mlRe: Cache Class review (low priority) Chris Hanson May 3, 04:24