in reply to Threads sharing a Cache::MemoryCache object??

Why not just use a shared hash instead?
  • Comment on Re: Threads sharing a Cache::MemoryCache object??

Replies are listed 'Best First'.
Re^2: Threads sharing a Cache::MemoryCache object??
by Wiggins (Hermit) on Aug 09, 2008 at 17:02 UTC
    Yes, that is a possibility. I like the cache because it has already figured out/coded how to do the aging process. But that brings up a fundamental question.

    "How well is the Object Oriented(OO) pattern supported within Perl Threads?" There must be a fundamental problem with objects memory management within the "shared" thread.

    While a hash, and thread to do the purging of expired entries might solve this specific problem; what about the general case? Might there be a "thread space" qualifier, just like a "name space" qualifier? This is a reference to the "rootthread::Cache::Cache" object...

      Hi, threads::shared says in its BUG AND LIMITATIONS section:
      It is often not wise to share an object unless the class itself has been written to support sharing. For example, an object's destructor may get called multiple times, once for each thread's scope exit.

      When trying to test your program, use strict; revealed that several variables are used without initialising them (e.g. precious $cacheRefShar). I have fiddled around with shared_clone() and Cache::MemoryCache but to no avail. Again, studying the documentation lead to Cache::SharedMemoryCache which helped a lot. So this works with Perl 5.8.8 (Linux). Here's a draft...