Cache: cache

Review Request #528 — Created Aug. 14, 2017 and submitted

p.valk
Lunr
cache2
2a326cb...
lunr

psuedocode example of how to implement it inside a controller.

public function foo()
    {
            $key = 'some unique identifier';

            $cache = new cacheprovider(...);

            $values = $cache->get($key);

            if ($values === FALSE)
            {
                $values = $api->get_entries($type, $filter);

                $cache->set($key, $values);
            }
        }

        // Return data.
        return $values;
    }


  • 0
  • 0
  • 38
  • 0
  • 38
Description From Last Updated
p.valk
p.valk
p.valk
pprkut
  1. Missing the composer changes

  2. decomposer.json (Diff revision 2)
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    unrelated to this review

  3. src/Lunr/Gravity/CacheController.php (Diff revision 2)
     
     
     

    Incomplete namespace declaration for params

  4. src/Lunr/Gravity/CacheController.php (Diff revision 2)
     
     
     
     
     

    why do we need this at all?

    1. looks cleaner and to make sure the key is the same in every function.

    2. for the record, single line private/protected functions are almost never worth it.

      It might be worth it here, but then you better have a very good argument for it

  5. src/Lunr/Gravity/CacheController.php (Diff revision 2)
     
     

    missing phpdoc

  6. src/Lunr/Gravity/CacheController.php (Diff revision 2)
     
     

    missing phpdoc

  7. src/Lunr/Gravity/CacheController.php (Diff revision 2)
     
     

    I don't see an isMiss() method in PSR-6

  8. src/Lunr/Gravity/CacheController.php (Diff revision 2)
     
     
     
     
     
     
     

    Why do we need to do this here? It has nothing to do with getting data from the cache.

    1. to make the implementation as easy as possible.
      i'l move it to a locking function.

    2. why do we need it in a locking function?

  9. src/Lunr/Gravity/CacheController.php (Diff revision 2)
     
     
     
     
     
     
     
     

    Incomplete documentation
    Order of params doesn't match implementation

  10. src/Lunr/Gravity/CacheController.php (Diff revision 2)
     
     
     
     
     
     

    I don't know what you mean with singleton, but this class should be completely reentrant. I should be able to call get() and set() in any order with any keys and it should work without causing side effects.

    1. ok, well then the implementation would need an extra call to lock the item while it is refreshing.

    2. Not following. Why do we need locking here?

  11. src/Lunr/Gravity/CacheController.php (Diff revision 2)
     
     
     
     
     
     

    no TTL in $config

    that's just too messy

    1. i tought you would prefer this over hardcoded, i can let it be a parameter to the set_cache function

    2. If you put this in a config file, you'd end up with a config file with a couple hundred entries (in large applications).

  12. tests/test.bootstrap.inc.php (Diff revision 2)
     
     
     
     
     
     

    unrelated to this review

  13. 
      
p.valk
pprkut
  1. 
      
  2. composer.json (Diff revision 3)
     
     
     

    should be up with the other php libs

  3. src/Lunr/Gravity/CacheController.php (Diff revision 3)
     
     

    protected $pool

  4. src/Lunr/Gravity/CacheController.php (Diff revision 3)
     
     

    not used anymore

  5. src/Lunr/Gravity/CacheController.php (Diff revision 3)
     
     
     
     
     
     
     

    "get" is enough.

    This will most likely be $cache->get(), so $cache->get_cache() would just have useless information.

  6. src/Lunr/Gravity/CacheController.php (Diff revision 3)
     
     
     
     
     
     
     
     
     
     
     
     
     

    superfluous comments

  7. src/Lunr/Gravity/CacheController.php (Diff revision 3)
     
     

    time to live

  8. src/Lunr/Gravity/CacheController.php (Diff revision 3)
     
     

    double bool

  9. src/Lunr/Gravity/CacheController.php (Diff revision 3)
     
     

    set() is enough

    a 30 second default is rather short. That's fine for really high traffic sites, but for low traffic sites that just means there won't ever be a cache hit. Make it like 5 or 10 minutes.

  10. src/Lunr/Gravity/CacheController.php (Diff revision 3)
     
     

    superfluous comment

  11. 
      
p.valk
pprkut
  1. 
      
  2. src/Lunr/Gravity/CacheController.php (Diff revision 4)
     
     
     
     
     

    please don't call it a controller. Controller methods are accessible via web/cli, which these clearly shouldn't be.

  3. src/Lunr/Gravity/CacheController.php (Diff revision 4)
     
     

    formatting

  4. src/Lunr/Gravity/CacheController.php (Diff revision 4)
     
     

    doesn't exist anymore

  5. src/Lunr/Gravity/CacheController.php (Diff revision 4)
     
     
     
     
     
     

    Incomplete phpdoc

  6. src/Lunr/Gravity/CacheController.php (Diff revision 4)
     
     
     
     
     
     
     

    you can do $item->get() inside the if statement

    1. i prefer doing it like this, looks cleaner. and you need to do ->isHit() anyway.

      or if you want smaller code change the if to return $item->isHit() === true ? $data : false;

    2. It's not about smaller code, it's about not storing useless data.

    3. nevermind my point above, confused 2 variables.

  7. src/Lunr/Gravity/CacheController.php (Diff revision 4)
     
     
     
     
     
     
     
     

    Incomplete phpdoc

  8. src/Lunr/Gravity/CacheController.php (Diff revision 4)
     
     

    I think it's easier to follow the code if you do this in two steps

  9. 
      
smillernl
  1. 
      
  2. src/Lunr/Gravity/CacheController.php (Diff revision 4)
     
     

    How can the parameter be int and still need to be cast to Int? Don't accomodate for people refusing to follow the rules.

  3. tests/test.bootstrap.inc.php (Diff revision 4)
     
     

    Naming here follows the namespace naming (making this wrong)

  4. 
      
p.valk
p.valk
smillernl
  1. 
      
  2. composer.json (Diff revision 5)
     
     

    Not required right?

  3. 
      
p.valk
pprkut
  1. 
      
  2. src/Lunr/Cache/Cache.php (Diff revision 6)
     
     

    This should be a type, not a variable name

  3. src/Lunr/Cache/Cache.php (Diff revision 6)
     
     

    We're not actually requiring any Stash specifics here, so we should depend on the PSR-6 interface only

  4. 
      
p.valk
pprkut
  1. 
      
  2. src/Lunr/Cache/Cache.php (Diff revisions 6 - 7)
     
     

    Full or relative namespace please

  3. 
      
pprkut
  1. 
      
  2. composer.json (Diff revision 7)
     
     

    we don't need stash anymore, only psr-6.
    Projects may choose stash as a psr-6 implementation

    1. so also remove it from composer, then only include the psr/cache

    2. i meant decomposer*

    3. yes to both

  3. 
      
p.valk
p.valk
smillernl
  1. 
      
  2. This should be Psr, can't have tests determine implementation

  3. tests/test.bootstrap.inc.php (Diff revision 8)
     
     
  4. 
      
p.valk
p.valk
Review request changed

Status: Closed (submitted)

Change Summary:

Merged into master

Loading...