May 5 09 / 124

ImageCache

In the process of building a site, I’m also attempting to build a solid library of classes I can re-use in future work to speed up the process. One simple, little class I’ve written is an internal image cache class to cache instances of loaded BitmapData keyed to their URLs. It can also be used [...]

In the process of building a site, I’m also attempting to build a solid library of classes I can re-use in future work to speed up the process. One simple, little class I’ve written is an internal image cache class to cache instances of loaded BitmapData keyed to their URLs. It can also be used to as a static reference for bitmaps you tend to reuse or need global access to; just use a unique string as the key. All methods are static, and the class cannot be instantiated.

Public static methods:

isCached( key:String ):Boolean
Returns true if the class is storing a bitmap under the key param.

store( key:String, bitmapData:BitmapData ):void
Stores the bitmapData under the key, will overwrite previous values.

retrieve( key:String, forgetOnRetrieve:Boolean = false):BitmapData
Returns the BitmapData stored under the key. Optional forget param to auto-run the forget method.

forget(key:String):void
Removes the class’ reference to the key param.

dispose( key:String ):Boolean
Runs BitmapData.dispose on the key’s BitmapData. Returns true if the class contains the key. Disposing a BitmapData will also destroy any non-cloned instances of this BitmapData, so be careful. Use forget if you just want to delete this class’ reference.

File here. Let me know how much it sucks:
http://lab.sibhod.com/ImageCache.as

No comments yet, be the first!

Leave a comment

Name (required)

Mail (required)

Website

Text