in reply to Re: Inside Out Classes with caching
in thread Inside Out Classes with caching

I haven't worked with any of the caching modules, so I'm curious to understand what the underlying issues are. If the object can be serialized, it can be cached, no? Is it just that it's easy to throw a hash-based object at the caching modules for serialization? Whereas with an inside-out object, you'd have to explicitly write freeze/thaw routines?

It also occurs to me that it may depend on how you construct the inside-out class. To perrin's point -- you may not want to use inside-out classes for this. Some of the typical benefits of inside out classes include

If you're caching, you're sort of explictly breaking encapsulation anyway for the purpose of efficiency, so unless the second point is important you may not need them..

On the other hand, there's no reason why you can't write an inside-out class that uses the blessed reference as the key to a hash with the value being a hash-reference containing the data. (Like a regular hash-based class, but with an extra level of indirection.) That preserves the ability to subclass anything and mostly keeps the strong encapsulation. It might then be easier/faster to write up a freeze/thaw routine to manipulate that underlying hash. (At which point you break encapsulation, but only via a class freeze/thaw routine.)

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^3: Inside Out Classes with caching
by perrin (Chancellor) on Sep 19, 2005 at 18:53 UTC
    Is it just that it's easy to throw a hash-based object at the caching modules for serialization? Whereas with an inside-out object, you'd have to explicitly write freeze/thaw routines?

    Yes. In theory, you could add something to Class::Std that works with Storable's hooks, but I don't think it's there already.