Krinkle added a comment.

  Yes, all keys passed to get/set must come from makeKey or makeGlobalKey from 
the same BagOStuff class.
  
  Where to call that depends on whether you intent to expose a general cache 
interface or one that has a finegrained purpose.
  
  Two examples. The generic one requires the caller to use (indirectly) use 
`makeKey`, and the caller is responsible for the TTL etc.
  
  name=MyAlternateCacheInterface.php
    use Wikimedia\LightweightObjectStore\ExpirationAwareness;
    class MyAlternateCacheInterface implements ExpirationAwareness {
        __construct(BagOStuff $cache) {
                $this->cache = $cache;
        }
        getKey ($keyspace, ...$components) {
                return $this->cache->makeKey($keyspace, ...$components);
        }
        fetch ($key) {
                return $this->cache->get($key);
        }
        store ($key, $val, $ttl = self:TTL_HOUR) {
                return $this->cache->set($key, $val, $ttl);
        }
    }
  
  The specific one takes care of that for you, and only provides getting and 
storing of specific things which have known key fragments.
  
  name=ThingCache.php
    class ThingCache {
      private const VERSION = 2;
      private const TTL = BagOStuff::TTL_HOUR;
        __construct(BagOStuff $cache) {
                $this->cache = $cache;
        }
        private getKey (string $name, int $width, int $height) {
                return $this->cache->makeKey('wikibase-thing-named', $name, 
$width, $height, self::VERSION);
        }
        getNamedThing (ThingDesc $desc) {
                return $this->cache->get($this->getKey($desc->name, 
$desc->width, $desc->height));
        }
        setNamedThing (ThingDesc $desc, array $thingData) {
                return $this->cache->set(
                        $this->getKey($desc->name, $desc->width, $desc->height),
                        $thingData,
                        self::TTL
                );
        }
    }

TASK DETAIL
  https://phabricator.wikimedia.org/T245396

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: Krinkle
Cc: Liuxinyu970226, Agusbou2015, Ladsgroup, hashar, brennen, Krinkle, 
Lydia_Pintscher, Jdforrester-WMF, WMDE-leszek, Addshore, Jakob_WMDE, Tarrow, 
Aklapper, Rosalie_WMDE, darthmon_wmde, Nandana, Lahi, Gq86, GoranSMilovanovic, 
QZanden, LawExplorer, _jensen, rosalieper, Scott_WUaS, Jonas, Wikidata-bugs, 
aude, Mbch331, Rxy, Jay8g, Krenair
_______________________________________________
Wikidata-bugs mailing list
Wikidata-bugs@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikidata-bugs

Reply via email to