Temporal Objects
Posted: Tue Oct 18, 2005 9:56 pm
I don't know the name for this pattern, so I'll refer to it as a "Temporary Object" (although it has different meanings in compiled languages). Basically, it's an object that expires after a certain amount of time passes. This may be set period from the creation of the object or the last access of the object. Good examples of temporary objects are "Remember Me" tokens, user sessions and captchas.
Edit - Feyd says they're called Temporal Objects. Well what do you know: http://www.martinfowler.com/eaaDev/TemporalObject.html talks about change control... hmm... we still haven't figure out the name.
These objects require good garbage collection, essentially queries that delete all objects from the database that have "expired". Generally, it's like "DELETE FROM `tokens` WHERE creation < ?" and ? is the cutoff integer timestamp.
I'm having a bit of trouble naming this variable though. Should there be both a "Creation" and "Lastaccess" variable, even when most cases only one is used? It seems to me that you could condense the two fields, although that could lead to ambiguity (like, do you update the field?)
I'm also juggling around with the idea of "expiry": instead of saving the creation/lastaccess time, you set the expiry time, and you've got a real easy cutoff (it's the current time). However, you sorta lose information, and you can't easily change around the expiration times of earlier tokens (I suppose it's possible). And then there's still the problem of figuring out whether or not the object needs to have the expiry field updated in the Layer Supertype (variable flag in the mapper, perhaps)?
And of course, better, less ambiguous names for these fields would be welcome.
Another problem: both the domain object and the data mapper have to be aware of the amount of time the object is considered "Fresh". Does this mean I need a Lifetime Registry for the object, do I stick in the mapper or the domain object or in both?
Sorry, I was just doing some coding and I noticed duplication but I'm not sure what I should factor it into. I need to get some stable, well written enterprise systems to take a look at...
Edit - Feyd says they're called Temporal Objects. Well what do you know: http://www.martinfowler.com/eaaDev/TemporalObject.html talks about change control... hmm... we still haven't figure out the name.
These objects require good garbage collection, essentially queries that delete all objects from the database that have "expired". Generally, it's like "DELETE FROM `tokens` WHERE creation < ?" and ? is the cutoff integer timestamp.
I'm having a bit of trouble naming this variable though. Should there be both a "Creation" and "Lastaccess" variable, even when most cases only one is used? It seems to me that you could condense the two fields, although that could lead to ambiguity (like, do you update the field?)
I'm also juggling around with the idea of "expiry": instead of saving the creation/lastaccess time, you set the expiry time, and you've got a real easy cutoff (it's the current time). However, you sorta lose information, and you can't easily change around the expiration times of earlier tokens (I suppose it's possible). And then there's still the problem of figuring out whether or not the object needs to have the expiry field updated in the Layer Supertype (variable flag in the mapper, perhaps)?
And of course, better, less ambiguous names for these fields would be welcome.
Another problem: both the domain object and the data mapper have to be aware of the amount of time the object is considered "Fresh". Does this mean I need a Lifetime Registry for the object, do I stick in the mapper or the domain object or in both?
Sorry, I was just doing some coding and I noticed duplication but I'm not sure what I should factor it into. I need to get some stable, well written enterprise systems to take a look at...