com. kelvinluck. flashr. core. FlashrCache

Class to cache relevant queries to flickr.com.

To use just set Flashr.cacheQueries to true.

Doing this means if you repeat a call to a given method with the same parameters then rather than spawning a repeated HTTP request to flickr.com the Flashr library will return the same results as the last call.

This has the advantage of reducing network traffic with flickr which can be a bottleneck in certain types of applications.  The downside is increased memory usage on the client as the results of all queries to flickr are held in memory.  For each application choose which is best for your needs - set Flashr.cacheQueries to true or false

By default, calls to the following methods are cached (where Flashr.cacheQueries is true)

flickr.contacts.getList flickr.contacts.getPublicList flickr.favorites.getList flickr.favorites.getPublicList flickr.groups.pools.getContext flickr.groups.pools.getGroups flickr.groups.pools.getPhotos flickr.interestingness.getList flickr.people.findByEmail flickr.people.findByUsername flickr.people.getInfo flickr.people.getPublicGroups flickr.people.getPublicPhotos flickr.photos.getAllContexts flickr.photos.getContactsPhotos flickr.photos.getContactsPublicPhotos flickr.photos.getContext flickr.photos.getCounts flickr.photos.getExif flickr.photos.getInfo flickr.photos.getNotInSet flickr.photos.getPerms flickr.photos.getRecent flickr.photos.getSizes flickr.photos.getUntagged flickr.photos.getWithGeoData flickr.photos.getWithoutGeoData flickr.photos.recentlyUpdated flickr.photos.search flickr.photos.comments.getList flickr.photos.geo.getLocation flickr.photos.geo.getPerms flickr.photosets.getContext flickr.photosets.getInfo flickr.photosets.getList flickr.photosets.getPhotos flickr.photosets.comments.getList flickr.tags.getListPhoto flickr.tags.getListUser flickr.tags.getListUserPopular flickr.tags.getRelated

If you would like more or less methods cached you can use the setCachable method.

Licence

This code and documentation is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.0.  http://creativecommons.org/licenses/by-nc-sa/2.0/

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Version

0.5.0

Author

Kelvin Luck < kelvin at kelvinluck dot com >

Project Website

http://flashr.kelvinluck.com/

Subversion Id

$Id: FlashrCache.as 72 2006-09-01 00:33:02Z kluck $

Summary
com. kelvinluck. flashr. core. FlashrCacheClass to cache relevant queries to flickr.com.
cachedMethodsHolds a list of all the methods whose results are cached.
FlashrCache
clearCacheClears the cache
getCachedReturns the cached FlashrResponseEvent for a given FlashrRequest or undefined if this request hasn’t been cached yet.
cacheCaches the passed FlashrRequest and it’s FlashrResponseEvent as long as it is a method that should be cached.
setCachableThis method gives you control over which flickr api methods will be cached.
_methodIsCachablePrivate, internal function which checks whether calls to a given method should be cached.
getInstance
toString

cachedMethods

var cachedMethods: Array

Holds a list of all the methods whose results are cached.

FlashrCache

private function FlashrCache()
Private constructorclass is a Singleton so instead use FlashrCache.getInstance

clearCache

function clearCache():Void

Clears the cache

getCached

function getCached(request: FlashrRequest):FlashrResponseEvent

Returns the cached FlashrResponseEvent for a given FlashrRequest or undefined if this request hasn’t been cached yet.

Parameters

requestThe FlashrRequest that you want to check.

Returns

Either the FlashrResponseEvent that was cached for this request or undefined if this FlashrRequest hasn’t been cached yet.

cache

function cache(responseEvent: FlashrResponseEvent):Void

Caches the passed FlashrRequest and it’s FlashrResponseEvent as long as it is a method that should be cached.

Parameters

responseEventThe FlashrResponseEvent that holds all information about the request response.

setCachable

function setCachable(methodName: String,
cachable: Boolean)

This method gives you control over which flickr api methods will be cached.

You can use it, for example, to ensure that calls to a given method are never cached.

Parameters

methodNameThe name of the flickr API method whose cachable status you want to change (e.g.  “flickr.photos.search”).
cachableWhether or not this method should be cachable

See Also

cachedMethods

_methodIsCachable

private function _methodIsCachable(methodName: String):Boolean

Private, internal function which checks whether calls to a given method should be cached.

Parameters

methodNameThe name of the method.

Returns

Whether or not calls to this method should be cached.

getInstance

static function getInstance():FlashrCache

toString

public function toString():String
var cachedMethods: Array
Holds a list of all the methods whose results are cached.
private function FlashrCache()
function clearCache():Void
Clears the cache
function getCached(request: FlashrRequest):FlashrResponseEvent
Returns the cached FlashrResponseEvent for a given FlashrRequest or undefined if this request hasn’t been cached yet.
Class to hold all the information that is dispatched as an event from Flashr when there is a response to a request.
Class to hold information about requests to the Flickr API through Flashr
function cache(responseEvent: FlashrResponseEvent):Void
Caches the passed FlashrRequest and it’s FlashrResponseEvent as long as it is a method that should be cached.
function setCachable(methodName: String,
cachable: Boolean)
This method gives you control over which flickr api methods will be cached.
private function _methodIsCachable(methodName: String):Boolean
Private, internal function which checks whether calls to a given method should be cached.
static function getInstance():FlashrCache
public function toString():String
var cacheQueries: Boolean
Sets whether the results of queries to flickr.com should be cached.