New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested NamespaceCachePools should trim the seperator #77

Open
SpazzMarticus opened this Issue Oct 12, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@SpazzMarticus

SpazzMarticus commented Oct 12, 2016

Nested NamespaceCachePools have multiple HIERARCHY_SEPARATORs concatted together.

Example:

$cachePoolApp=new \Cache\Namespaced\NamespacedCachePool($cachePool, 'app-name');
$cachePoolVersion=new \Cache\Namespaced\NamespacedCachePool($cachePoolApp, 'code-version');
$cachePoolInstance=new \Cache\Namespaced\NamespacedCachePool($cachePoolVersion, 'instance-id');

Saving to key test will generate the key |app-name||code-version||instance-id|test.
I expected app-name|code-version|instance-id|test to be the key.

Are the multiple seperators planned behaviour?

(Is the prefixed seperator |app-name necessary? It seems a bit odd.)

@Nyholm

This comment has been minimized.

Show comment
Hide comment
@Nyholm

Nyholm Oct 18, 2016

Member

Thank you for reporting this. That is something I did not anticipated.

Can I ask you about your use case? Why would you need nested namespaces?

Member

Nyholm commented Oct 18, 2016

Thank you for reporting this. That is something I did not anticipated.

Can I ask you about your use case? Why would you need nested namespaces?

@SpazzMarticus

This comment has been minimized.

Show comment
Hide comment
@SpazzMarticus

SpazzMarticus Oct 24, 2016

In my case I have multiple instances (database schemata) running with the same codebase, so each cache key should be in a namespace with the instance-id (lets call this the main cache). Some features have special caching, so they take the main cache and add a namespace in which the cache keys are then stored.

E.g. main cache |1234|<key>, special cache |1234|special|<key>

SpazzMarticus commented Oct 24, 2016

In my case I have multiple instances (database schemata) running with the same codebase, so each cache key should be in a namespace with the instance-id (lets call this the main cache). Some features have special caching, so they take the main cache and add a namespace in which the cache keys are then stored.

E.g. main cache |1234|<key>, special cache |1234|special|<key>

@Nyholm

This comment has been minimized.

Show comment
Hide comment
@Nyholm

Nyholm Oct 25, 2016

Member

Interesting.. Im not sure if this would be a good general solution. But is it possible to do something like:

// Namespaced cache
    private function prefixValue(&$key)
    {
        // |namespace|key
        $key = '';
        if (! $this->cachePool instanceof NamespacedCache) {
             $key = HierarchicalPoolInterface::HIERARCHY_SEPARATOR.
        }
        $key.= $this->namespace.HierarchicalPoolInterface::HIERARCHY_SEPARATOR.$key;
    }

This will not work if you namespaced cache is wrapped in some other cache.

Member

Nyholm commented Oct 25, 2016

Interesting.. Im not sure if this would be a good general solution. But is it possible to do something like:

// Namespaced cache
    private function prefixValue(&$key)
    {
        // |namespace|key
        $key = '';
        if (! $this->cachePool instanceof NamespacedCache) {
             $key = HierarchicalPoolInterface::HIERARCHY_SEPARATOR.
        }
        $key.= $this->namespace.HierarchicalPoolInterface::HIERARCHY_SEPARATOR.$key;
    }

This will not work if you namespaced cache is wrapped in some other cache.

@SpazzMarticus

This comment has been minimized.

Show comment
Hide comment
@SpazzMarticus

SpazzMarticus Oct 25, 2016

I used this:

$key = $this->namespace.HierarchicalPoolInterface::HIERARCHY_SEPARATOR.trim($key, HierarchicalPoolInterface::HIERARCHY_SEPARATOR);

SpazzMarticus commented Oct 25, 2016

I used this:

$key = $this->namespace.HierarchicalPoolInterface::HIERARCHY_SEPARATOR.trim($key, HierarchicalPoolInterface::HIERARCHY_SEPARATOR);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment