Branch: Tag:

2017-02-23

2017-02-23 13:49:25 by Martin Karlgren <marty@roxen.com>

CM_GDS_Time.got_hit: Only save start hrtime if cache prefs say so.

This saves some time on most cache hits.

212:    }   }    + class CacheManagerPrefs(int(0..1) extend_entries // Set if a +  // cache_name may get +  // existing entries +  // extended even +  // after cache hit. +  ) {} +    class CacheManager   //! A cache manager handles one or more caches, applying the same   //! eviction policy and the same size limit on all of them. I.e. it's
256:    //! For functions in this class, a @[CacheStats] object does not    //! exist only due to race, so the cache should just be ignored.    +  mapping(string:CacheManagerPrefs) prefs = ([]); +  //! Preferences for the named caches managed by this object. +  //! +     int cached_overhead_add_count;    //! Snapshot of @[entry_add_count] at the point the manager overhead    //! was computed.
1062:    void got_hit (string cache_name, CacheEntry entry, mapping cache_context)    {    ::got_hit(cache_name, entry, cache_context); -  // It shouldn't be necessary to record the start time for cache -  // hits, but do it anyway for now since there are caches that on -  // cache hits extend the entries with more data. +  if (CacheManagerPrefs prefs = prefs[cache_name]) { +  if (prefs->extend_entries) { +  // Save start time for caches that may want to extend existing +  // entries.    save_start_hrtime (cache_name, entry->key, cache_context);    } -  +  } +  }       protected int entry_create_hrtime (string cache_name, mixed key,    mapping cache_context)
1514:   }      CacheManager cache_register (string cache_name, -  void|string|CacheManager manager) +  void|string|CacheManager manager, +  void|CacheManagerPrefs prefs)   //! Registers a new cache. Returns its @[CacheManager] instance.   //!   //! @[manager] can be a specific @[CacheManager] instance to use, a
1547:    caches[cache_name] = manager;    manager->stats[cache_name] = CacheStats();    manager->lookup[cache_name] = ([]); +  if (prefs) +  manager->prefs[cache_name] = prefs;    return manager;   }