Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: API rate limit using Cache::Mmap need help

by jcb (Parson)
on Jul 27, 2020 at 03:00 UTC ( [id://11119855]=note: print w/replies, xml ) Need Help??


in reply to API rate limit using Cache::Mmap need help

While I am unfamiliar with Cache::Mmap, your error suggests that it is using Storable internally. You are trying to store a simple value, but Storable only works with references. Try changing your code like so: (untested)

my $key1 = "Test"; my $val1 = $cache->read($key1); print "read key1 count: ",$val1->{count},"\n"; $val1->{count}++; print "val1 count:",$val1->{count},"\n"; $cache->write($key1,$val1); $val1 = $cache->read($key1); print "read key1 count after write: ",$val1->{count},"\n";

Note the change: the values stored in the cache are now hashrefs. You could also use scalar references, reading them with $$val1 and incrementing with ${$val1}++.

Lastly, your code as written will not compile under strict. While it would not have caught this issue, good practice is to always use strict; and use warnings;.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found