Question

I have some objects stored in Cache via putCache() The objects in cache have a timeout of 10 minutes.

These objects are shared among all users. However, there are 2-3 variables that are user-dependant. Currently each object stores these user-dependant variables in the user session.

Problem:

When the component is removed from cache after 10 minutes the variables in user session are not deleted. So maybe after 12 minutes the object is created again and will write 2 new variables to user session
Note: Each object will create a new struct in session-scope with an unique name. The old variables cannot be overwritten since the new object does not know the struct name of the previous object.

Example: Object is "list.cfc" there can be 20 different lists, each stores completely different data. In session we only store the "list_position" of the current user; the list_items are stored in cache and are same for all users.

We want to clean the session-variables when an object is destroyed. How can this be done?

The idea: In php I would use the __destruct() method, but I could not find an equivalent of this in ColdFusion.

Was it helpful?

Solution

Surely the easiest way is to abstract the naming of your session variables so that you can reference them directly. EG: it sounds like currently you have this:

// in Cache.cfc
// [...]
someVarInTheCache = sessionReference[uniqueKey]

And your object doesn't know that key?

Can you not just do this:

someVarInTheCache = sessionReference.someVarRepresentingTheCache[uniqueKey]

And then when you kill the Cache, you just kill session.someVarRepresentingTheCache, and don't need to know the key.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top