Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by phildeman (Scribe)
on May 19, 2021 at 19:41 UTC ( #11132745=perlquestion: print w/replies, xml ) Need Help??

phildeman has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am using CHI to cache data. In the documentation it shows the use of global => 1. For example:

my $cache = CHI->new( driver => 'Memory', global => 1 );

However, the documentation does not explain the use of the key, 'global'.
I tried searching it on Google, but the results I get back do not explain it's
usage. Does anyone know what this hash key signifies?

Thanks.

Replies are listed 'Best First'.
Re: What does the hash key, global => 1, do in CHI
by Fletch (Chancellor) on May 19, 2021 at 19:46 UTC

    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.

      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.

Re: What is global => 1 in CHI
by haukex (Bishop) on May 19, 2021 at 19:45 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11132745]
Approved by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2021-09-26 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?