CacheMoney HTTPServices

Suppose you're developing a Flex application which retrieves data from a server outside your realm of control, dictating a HTTP caching policy which clashes with your general well-being. Or, suppose you wish to implement a caching mechanism on the Flex client application that is a bit more elaborate than a simple document expiration scheme. Now, suppose you wish to implement this functionality in an elegant, low-maintenance manner.

The best way I've found to go about this is by extending mx.rpc.http.mxml.HTTPService and overriding the send() method. Using a little bit of AOP-style, result-handling kung-fu, along with an extended mx.rpc.events.ResultEvent that allows writing to the result property, calls can be made to this CachedHTTPService as you would normally expect, but behind the scenes the result is built either from cache (if it has already been populated) or from the original intended URL. No caching logic to muck up your business logic.

    CachedHTTPService.as

    Example Call:

(CachedHTTPService is defined and called just like HTTPService, only requiring an additional parameter, the CacheManager Implementation you wish to tie into)

Here is the CachedHTTPService Source, including the CacheManager interface and example implementation, as well as the WriteableResultEvent. Have fun!


About this entry