Nameless icon indicating copy to clipboard operation
Nameless copied to clipboard

Cache DX improvements

Open tadhgboyle opened this issue 2 years ago • 0 comments

  • "Setting" the cache seems like a strange concept, and easy to forget to do, resulting in missed cache hits commonly (probably all over our code atm)
    • An alternative would be to support a 'key:value' string to the retrieve (or get) method, which we use 'key' for the file, and 'value' for the value within the file. If they don't provide a key, then we would use 'value' for the file name. This keeps cache files to a minimum but also simplifies the use of cache
  • Allowing to get/set in one call:
    / Currently:
    cache->setCache('user_cache');
    f ($cache->isCached('users') {
     $users = $cache->retrieve('users');
     else {
     $users = DB::getInstance()->get('users')->results();
     $cache->store('users', $users, 60);
    
    
    / Future:
    users = $cache->get('users', function () {
     return DB::getInstance()->get('users')->results();
    , 60);
    
    • Really annoying to write 8 lines of code to set cache, check if cached (retrieve if so), otherwise store and then return cached value. Doing something which allows to set the value if not cached would make it so much easier and nicer to use the cache system around the codebase.
  • Create/get debugbar cache collector to display hits and misses

tadhgboyle avatar Jan 20 '23 08:01 tadhgboyle