in reply to What does the hash key, global => 1, do in CHI

There's documentation in CHI::Driver::Memory

global [BOOL]
Use a standard global datastore. Multiple caches created with this set to true will see the same data. Before 0.21, this was the default behavior; now it must be specified explicitly (to avoid accidentally sharing the same datastore in unrelated code).

If this is set to false then datastore will be set to a new reference to a hash.

The cake is a lie.
The cake is a lie.
The cake is a lie.

  • Comment on Re: What does the hash key, global => 1, do in CHI

Replies are listed 'Best First'.
Re^2: What does the hash key, global => 1, do in CHI
by phildeman (Scribe) on May 20, 2021 at 16:12 UTC

    Hi Fletch,

    Thanks for the quick response. I used $cache = CHI->new( driver => 'Memory', global => 1 ); as an example
    to show how 'global => 1' was being used. I am not instantiating the CHI class that way. Actually, I am using:

    my $cache = CHI->new( driver => 'File', root_dir => '/path/to/my_cache_dir' );

    The documentation does not show the use of 'global => 1' with that example. I was curious why and when it is necessary to use it.

      global is an argument specifically for the "Memory" (CHI::Driver::Memory) driver. If you're using a different driver then you'd consult the documentation for the custom options that particular implementer uses (i.e. CHI::Driver::File for the relevant options for that module).

      Edit: Just to expound on this, the docs for CHI show the common constructor options that are available irrespective(*) of the driver being used; anything specific to a given driver module would be documented with the driver module.

      (*) I'm not really familiar with CHI so conceivably there could be some options that are incompatible with some drivers but I'm not aware if that's actually the case; the documentation for the individual drivers would say for sure were that the case.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.