Code Monkey home page Code Monkey logo

perl-chi's People

Contributors

asb-capfan avatar autarch avatar bits avatar chorny avatar haarg avatar jonswar avatar jraspass avatar jrouzierinverse avatar karenetheridge avatar manwar avatar rouzier avatar sshine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

perl-chi's Issues

not really an issue , but a question

if I've the below code

my $cache = CHI->new( driver => 'FastMmap',
root_dir => '/Users/xyz',
cache_size => '1k'
);

and this is part of a perl cgi script, how do I avoid the creation of cache every time the script is invoked

I want to persist a connection across multiple http post calls

  • first http call will create the cache and store the connection
  • subsequent ones need to only fetch the connection from cache

Category used for Log::Any

I think the documentation needs a little extra when it describes Logging. It mentions that logging is done through Log::Any, but neglects to mention the category, which is CHI::Driver.

Feature request - active method for cache instance

Good day!

I want to prevent storm of 'compute' method if i have CHI & Memcached and if Memcached is not working already during runtime. Now a get & set methods of Memcached's modules don't die if connection is dropped. And i will not know in program code if memcached will die - no die from theirs - no errors in CHI (CHI catches errors from drivers through die from get & set)...

If i use compute method that after if memcached will die i will get a big problems - every time my $code of compute will run again & again -> i will get a snowball effect.

I think better way will introduce new method for cache instance - 'active' - if our driver of cache functions properly (for memcached this status of connect but i didn't find it there now - i will ask the author of Cache::Memcached::Fast & Cache::Memcached to add it) active will return true else false. If this method will be i will be able to check this status inside 'compute' and if status is not active - rise error through die or to return undef.

There is other way may be. To ask an authors of Cache::Memcached* modules to add die from get & set as an option.

What is your opinion?

Thanks

t/smoke-Driver-NonMoose.t is flapping - CHI::Test::Driver::NonMoose:l1_cache size

I noticed this error while building CHI with Perl 5.26
and can noticed that t/smoke-Driver-NonMoose.t was randomly failing
Failed test 'CHI::Test::Driver::NonMoose:l1_cache size = 40'
Failed test 'CHI::Test::Driver::NonMoose:l1_cache keys = 2'

rebuilding it fixes the issue for me, I've not investigated the source of the problem
but there could be something wrong there

# Testing CHI 0.60, Perl 5.026000, /usr/local/cpanel/3rdparty/perl/526/bin/perl
t/00-load.t ............................. ok
t/author-03-pod.t ....................... skipped: these tests are for testing by the author
t/author-file-driver.t .................. skipped: these tests are for testing by the author
t/author-no-data-serializer.t ........... skipped: these tests are for testing by the author
t/author-RequiredModules.t .............. skipped: these tests are for testing by the author
t/Bugs.t ................................ ok
t/Config.t .............................. ok
t/Constants.t ........................... ok
t/Driver-Memory.t ....................... ok
t/Driver-RawMemory.t .................... ok
t/GetError.t ............................ ok
t/Initialize.t .......................... ok
t/release-dependent.t ................... skipped: these tests are for release candidate testing
t/Sanity.t .............................. ok
t/SetError.t ............................ ok
t/smoke-Driver-CacheCache.t ............. skipped: one of required modules not installed: Cache::Cache
t/smoke-Driver-FastMmap.t ............... skipped: one of required modules not installed: Cache::FastMmap
t/smoke-Driver-File-DepthZero.t ......... ok
t/smoke-Driver-File.t ................... ok
# 40 is not between 59 and 99

#   Failed test 'CHI::Test::Driver::NonMoose:l1_cache size = 40'
#   at /home/rpmbuild/rpm-build/BUILD/CHI-0.60/blib/lib/CHI/t/Driver.pm line 1555.
#   (in CHI::t::Driver::NonMoose->test_size_awareness_with_subcaches)
# 2 is not between 3 and 5

#   Failed test 'CHI::Test::Driver::NonMoose:l1_cache keys = 2'
#   at /home/rpmbuild/rpm-build/BUILD/CHI-0.60/blib/lib/CHI/t/Driver.pm line 1557.
#   (in CHI::t::Driver::NonMoose->test_size_awareness_with_subcaches)
# Looks like you failed 2 tests of 874.
t/smoke-Driver-NonMoose.t ............... 
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/874 subtests 
	(less 1 skipped subtest: 871 okay)
t/smoke-Driver-Subcache-l1_cache.t ...... ok
t/smoke-Driver-Subcache-mirror_cache.t .. ok
t/smoke-Null.t .......................... ok
t/Subcache.t ............................ ok
t/Subclass.t ............................ ok
t/Util.t ................................ ok

Test Summary Report
-------------------
t/smoke-Driver-NonMoose.t             (Wstat: 512 Tests: 874 Failed: 2)
 Failed tests:  863-864
 Non-zero exit status: 2
Files=26, Tests=5218, 11 wallclock secs ( 0.57 usr  0.06 sys +  8.49 cusr  0.94 csys = 10.06 CPU)
Result: FAIL
Failed 1/26 test programs. 2/5218 subtests failed.
make: *** [test_dynamic] Error 255
error: Bad exit status from /var/tmp/rpm-tmp.5yDawl (%check)

Race condition in CHI::Driver::Role::IsSizeAware

1

Race condition in discard_to_size():

setup

$cache = CHI->new(
namespace	=> 'resizeimg',
expires_in	=> '5 d',
max_size	=> int(10.01 * 1024*1024), # M
driver		=> 'File',
depth		=> 3,
);

and die in concurency at line 127, when one process working on clean keys from cache in while { } when second process got keys to clean but got empty list (because the final size is not written to cache store in the first process yet) then enter in else { } and die in eval as affirm (line 129) then at line 138

Assertion (iterator returned undef, cache should be empty) failed!
 at /usr/local/lib64/perl5/5.36/Carp/Assert.pm line 341.
        Carp::Assert::affirm(CODE(0x55e658a67468), "iterator returned undef, cache should be empty") called at /usr/local/lib64/perl5/5.36/CHI/Driver/Role/IsSizeAware.pm line 129
        eval {...} called at /usr/local/lib64/perl5/5.36/CHI/Driver/Role/IsSizeAware.pm line 118
        CHI::Driver::Role::IsSizeAware::discard_to_size(CHI::Driver::File__WITH__CHI::Driver::Role::Universal__AND__CHI::Driver::Role::IsSizeAware=HASH(0x55e658642e58), 8396996) called at /usr/local/lib64/perl5/5.36/CHI/Driver/Role/IsSizeAware.pm line 71
        CHI::Driver::Role::IsSizeAware::__ANON__(CODE(0x55e65892d6e0), CHI::Driver::File__WITH__CHI::Driver::Role::Universal__AND__CHI::Driver::Role::IsSizeAware=HASH(0x55e658642e58), "/var/www/nestormedia/testsite/img/pages/647-s.jpg;f=webp;w=40"..., CHI::CacheObject=ARRAY(0x55e658a66f58)) called at (eval 93) line 1
        CHI::Driver::File__WITH__CHI::Driver::Role::Universal__AND__CHI::Driver::Role::IsSizeAware::__ANON__(CHI::Driver::File__WITH__CHI::Driver::Role::Universal__AND__CHI::Driver::Role::IsSizeAware=HASH(0x55e658642e58), "/var/www/nestormedia/testsite/img/pages/647-s.jpg;f=webp;w=40"..., CHI::CacheObject=ARRAY(0x55e658a66f58)) called at (eval 95) line 2

Need to remove affirm at line 127.

2

I don't think we should ever die outside eval in discard_to_size at line 138

Driver::Memory high memory consuption

Driver::Memory is tracking usage of keys to fulfill LRU discard policy.
However ->get() method track last used time even for keys that are not known.
Therefore memory consumption for each "missed" hit will grow and is never released.

IMHO LRU policy is applicable (access should be traced) only for keys which are in cache.

Sample code to demonstrate:
#!/usr/bin/perl
use CHI;
my $_cache = CHI->new( driver => 'Memory', max_size => 1024, global => 1);
for (0 .. 100_000_00){
my $key = rand(10000000);
$_cache->get ( $key ); # memory consumption will hit a sky
}

Pull request:
#33

Feature request - setting of namespace from method (not only from constructor)

Good day!

Sometimes i very need to setup namespace for CHI cache during runtime not from constructor but from method.
For example i use Dancer for application and one Dancer will have a some sites inside itself. I can use Dancer::Plugin::Cache::CHI but i cannot change a namespace between applications (for separation of sites).

Is it possible to add this feature at near time?
Or if you have not a free time for this please let me know - i can try to add this feature myself. I am interested your plans about this feature

Thanks!

I want to make a patch for CHI - please approve my ideas before :-)

Good day!

Thanks for useful module!

But i need now in some feature, i can make it myself but before i decide to ask you for approving because i want to see it feature in next releases of CHI ;-)

Idea is a following:

I want to make a feature as Unix make command has. It feature is needed as i think. For example multi-page breaking of each page will depend from whole piece of data for all pages. And if i will cache this whole data piece and define compute method for it, i will want to recompute every page cache if this main whole data piece was changed (page's compute $code will only make like splice method for it of whole piece)

For it i want to add a new features to $cache->compute method:

  1. Every key of compute can be used as 'target' like make. target name == $key of compute (for example if $cache->compute has a certain options)

  2. Every target will be like trigger with his timestamp (like empty files of targets in make utility). Targets will be kept in other namespace with same key as compute's $code and they will may be as a flat numbers of time() or Time::HiRes::time() for example.

  3. Every compute's $code can have some dependences ('prerequisite' term of make) - list of targets with their $code's

  4. CHI if does 'compute' method which has a dependences for it (i am thinking about API now) will look in ones and if current object in cache is not expired but its target ($key) older than target(s) of dependence(s) - it will recompute $code and after will refresh target's trigger time. Of cause it should look up dependeces of dependences recursively for it (every time of compute method). But target triggers will be very small and i think it will not decrease performance dramatically - especially if this behavior will be optionally through certain options of compute method. I know about expire_if option of get but like implementation of this idea for it very cumbersome.

Please tell me your opinion of this

Thanks!

// Perlover :-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.