variable persistance in plack

31 views
Skip to first unread message

Joseph Norris

unread,
Nov 24, 2015, 9:05:00 AM11/24/15
to psgi-plack
Hello to all,

Again with the newbie questions.

I am attempting to maintain persistence in variables outside of the plack cycle.  I need to continue to accumulate data in a variable structure and add to and take away from between iterations of the run cycle of a plack script. 

What is the best way to do this?  Thanks for your help.

Ævar Arnfjörð Bjarmason

unread,
Nov 24, 2015, 9:07:15 AM11/24/15
to psgi-...@googlegroups.com
You can just declare a package-level variable and continue adding to that.

Keep in mind though that this will only do what you except on a server
that runs one webserving child. A normal Plack setup will fork your
processes and serve them independently.

Then if you need machine-level shared storage you'd stick it in a
local Redis, or if you have a bigger system you'd have the Plack
children send something down a message-bus after every request and
accumulate that.
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "psgi-plack" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to psgi-plack+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Joseph Norris

unread,
Nov 24, 2015, 9:41:41 AM11/24/15
to psgi-plack

Thank you for your response.  Ahh so from your email I am understanding my issue. There is not the method to pass messages between children in this installation of plack.  Would something like MemCache do the job? When you use the phrase "local Redis" what do you mean by this?  - thanks again.

Ævar Arnfjörð Bjarmason

unread,
Nov 24, 2015, 9:52:46 AM11/24/15
to psgi-...@googlegroups.com

Yeah memcache would work. Redis is just another memcache-like solution for the purposes of this discussion.

Joseph Norris

unread,
Nov 24, 2015, 11:17:00 AM11/24/15
to psgi-plack

Ok - got MemCached working in my application - thank you for your help.  One last question:   When my web application uses memcache and I do $cache->set('tag',$hash); Do I have to figure out some way to have a unique tag for each run of my application or does MemCache take care of this?

Thanks again

Dave Cross

unread,
Nov 24, 2015, 11:26:38 AM11/24/15
to psgi-...@googlegroups.com

Memcached is a key-value store. It takes the value you give it and
stored it against the key that you give it. Later on, you can give it
the key again and it will return you the value stored against that key.

If you want multiple values stored, then you will need to give them
separate keys. Memcached only ever uses the keys you give it. It
doesn't change them in any way.

In your example, the key is "tag". So your $hash is stored against
"tag" in Memcached. If you want a different instance of your
application to have a different $hash, then you will need to generate
a different key.

Cheers,

Dave...

Quoting Joseph Norris <joze...@gmail.com>:

> Ok - got MemCached working in my application - thank you for your help.
> One last question: When my web application uses memcache and I do
> $cache->set('tag',$hash); Do I have to figure out some way to have a unique
> tag for each run of my application or does MemCache take care of this?
>
> Thanks again
>
>
> On Tuesday, November 24, 2015 at 7:52:46 AM UTC-7, Ævar Arnfjörð Bjarmason
> wrote:
>
>> Yeah memcache would work. Redis is just another memcache-like solution for
>> the purposes of this discussion.
>> On Nov 24, 2015 3:41 PM, "Joseph Norris" <joze...@gmail.com <javascript:>>

Joseph Norris

unread,
Nov 24, 2015, 12:04:33 PM11/24/15
to psgi-plack
Thanks for your response.  So is there some unique identifier in the plack stack that could be used as part of my "tag"?

Aristotle Pagaltzis

unread,
Nov 24, 2015, 1:41:38 PM11/24/15
to psgi-...@googlegroups.com
* Joseph Norris <joze...@gmail.com> [2015-11-24 18:05]:
> So is there some unique identifier in the plack stack that could be
> used as part of my "tag"?

Well… a unique identifier of what? Do you need one per worker, or per
request, or per session, or…?
Reply all
Reply to author
Forward
0 new messages