Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Expanded resources and caching #48

@dkvk

Description

@dkvk

When caching expanded resources the key being used is not consistent.

The cache key that is used for cacheing a resource is based on the resource href as well as its options. This is done in

private function createKey($href, $options)
{
$key = $href;
if(!empty($options)) {
$key .= ':' . implode(':',$options);
}
return $key;
}

The problem when a resource gets updated and saved the key being used to first delete it from the cache is just based on the href:

$this->cache->delete($resource->getHref());

and not with its options.

As example, we always fetch accounts with expansion of its groups. The account data is saved to a cache key as:

  1. https://api.stormpath.com/v1/accounts/7BVwoUmoMCfWdxrHOjtLm4:groups

Later we update and save changes to the account, the cache key will then be:
2. https://api.stormpath.com/v1/accounts/7BVwoUmoMCfWdxrHOjtLm4
which gives a miss as that key does not exist.

Second, the data is saved to the same key:
3. https://api.stormpath.com/v1/accounts/7BVwoUmoMCfWdxrHOjtLm4
which then holds the newly updated data.

Later we fetch the same account with expansion of its groups. The key for that will be:
4. https://api.stormpath.com/v1/accounts/7BVwoUmoMCfWdxrHOjtLm4:groups
which of course doesn't include the newly updated data, but the data from the 1. fetch.

I would suggest a solution to this to just skip the options our from the key creation. Which would keep the same cache key over the whole lifecycle of the cached item. Also it would work incremental as when ever new data is expanded it would be saved to the cached item (overwritten).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions