tractorcow / silverstripe-dynamiccache

Simple on the fly caching of dynamic content for Silverstripe
39 stars 27 forks source link

WIP: feat(CacheMeta): Changed DynamicCache dramatically (breaking changes) #63

Closed silbinarywolf closed 6 years ago

silbinarywolf commented 6 years ago

Changed DynamicCache so that each page has 1 cache key (or file) per URL, the page can store metadata about the page that can be accessed during updateCacheKeyFragments()

I'm not expecting this PR to go in as is, but maybe we can reach a middle-ground on achieving something like this.

The use case for this is that I want to be able to cache variants of certain page types if a user has set their location to certain cities.

public function updateCacheKeyFragments(array &$fragments, array $meta) {
    if (isset($meta['Record']['ClassName']) && $meta['Record']['ClassName'] === 'MySpecificPage') {
       $fragments[] = singleton('Location')->getCityID();
    } else {
      $fragments[] = false;
    }
}

Related issue: https://github.com/tractorcow/silverstripe-dynamiccache/issues/62

silbinarywolf commented 6 years ago

@tractorcow If you have a second to look over this, that'd be great.