Thanks for all your ideas everyone - they definatley helped.

I wrote up a blog post on some of the issues I found and ways around
them when using external Java libs, in case you are interested.

http://www.compoundtheory.com/?action=displayPost&ID=114

I'm quite happy about working out how to get CF to reflect and invoke
constructors for you, rather than having to do it via Java reflection
APIs.  It makes life rediculously easy.

(Oh yeah - Peter, you could always use one of the PriorityQueue
classes from the Jakarta Commons Collection classes that are bundled
in with CF... undocumented, but very handy)

Mark

On 5/9/06, Peter J. Farrell <[EMAIL PROTECTED]> wrote:
 Mark you might consider using a LRU (least recently used) cache for caching
a finite amount of objects.  Consider that you want ten items in your cache.
 You have an array that is 10 items long.  The position in the array denotes
how recently used the object is.  New objects get pre-appended to the array
- which will automatically knock off the 10th (now 11th) item.  Objects that
already exist in the cache - say abcSerivce which is in the 7th position --
will be moved from 7 to 1.  Items after the tenth position are deleted off
the array.

I used LRU type cache in LylaCaptcha however instead of having to maintain
items for infinite amount of time -- I just needed to make sure that items
were around for a finite amount of time.  So what I did was have an array
with a length of two in which there was a struct in each.  New items were
always appended to the first array's struct.   On init of this array, I set
a tick count.  Whenever a new item is appended to the array - it checks if
the current tick count is over a certain threshold (say 120 seconds).  If
that is that case, it bumps the 1 part of the array to 2 and creates a new
blank struct in the first position.  The third part of the array is just
deleted because it was expired.  It's sorta like a poor man's LRU (although
really fast because you're not scanning each struct element just checking if
the time is over the threshold and bumping it down a slot and deleting an
array position).

Unless you are managing a ton of objects in the cache - moving things around
the array shouldn't be a problem  especially if you don't scan for garabage
collection each request.  You might consider only scanning for expired
objects on every tenth request to cache -- it's not necessary that things
expire exactly on time -- they just need to expire sometime "soon", but
accurately.  You might consider that when new objects are added to the cache
-- things are bumped around, but the clean only occurs when asking for
sometime that already exists (and only every tenth time or something).

Ok, done rambling late at midnight!

HTH and Best,
.Peter



--
E: [EMAIL PROTECTED]
W: www.compoundtheory.com
ICQ: 3094740


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to