Hi all,

Just thought I'd throw in a couple of thoughts into the discussion -

Firstly you don't need to do 'myFuncRef.toString()' to get the java 
class name, just get myFuncRef, for example:

<cfset key = hash(myFuncRef)/>

Don't know if anyone's done it already, but an interesting benefit of 
this is that you can use them as a sort of pointers to functions.

Another point is that the string you get from the function itself (i.e. 
[EMAIL PROTECTED]) changes with every change of 
that file because CF recompiles it.

So if you changed the function that you're caching the data from, you'd 
end up with a new copy of the data for every change.

If I were you, I'd use the location to the function and the function 
name because as mentioned earlier, it's probably going to be unique.



Tim Blair wrote:

> Evening,
> 
> I'm in the process of creating an application, part of which is a series
> of CFCs which perform and cache data, allowing quick retrieval on the
> next call.  This is done by passing a reference to a function to a
> method of a CFC which then runs the function after doing some other
> processing and returns the data.
> 
> Now I want to be able to cache the data generated.  The generated data
> will be plain text and so I'm just planning on storing it (keyed on
> something that uniquely identifies the funciton used) within an
> structure as an instance variable in the CFC.
> 
> So basically, I need a way to generate a structure key based on a
> reference to a function.  The way I've come up with is simply a hash of
> the toString of the function, prefixed with an arbitrary string so the
> variable name is valid, as so:
> 
> <cfset this.KEYPREFIX = "i">
> <cfset key = this.KEYPREFIX & hash(myFuncRef.toString())>
> 
> Which results in a key of "i8CF622BA70E703A796DB0FD8AC8ABFA8" -- a valid
> variable name and unique to the function called.
> 
> The myFuncRef.toString() returns an output similar to
> "[EMAIL PROTECTED]" which is basically the
> associated compiled java class.  AFAIK this uniquely identifies the
> function being used and means I don't have to manually associate an ID
> with each function.  The hash() + the string prefix call makes sure that
> any invalid chars get removed and the chance of two hash() calls
> returning the same value is supposedly around 1 in 2^64 so it should be
> safe there...
> 
> Basically, does anyone see any issue with doing it this way?
> 
> Tim.
> 
> 


-- 
  Oliver Tupman
  Key Systems Geotechnical

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/lists.cfm?link=t:4
Subscription: http://www.houseoffusion.com/lists.cfm?link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Get the mailserver that powers this list at 
http://www.coolfusion.com

Reply via email to