Code Monkey home page Code Monkey logo

Comments (2)

veewee avatar veewee commented on June 14, 2024

Hi @mathielen,

Thanks for your question! Currently, this library is at it's first version so it still has some things in it that could be better.
The problem you are facing is that the keygenerator is only taking the method arguments to generate it's key.
This means that by default, it will not take the method name into account when generating a key.
See: https://github.com/phpro/annotated-cache/blob/master/src/Phpro/AnnotatedCache/Interceptor/CacheableInterceptor.php#L122

The key generation part is pretty much copied from the TbbcCacheBundle. In a next version I want to change the KeyGeneratorInterface. The new interface should be able to handle the interception parameters as well (class name, method, returnValue).

To temporary fix your problem, there are 2 solutions:

  • Add the key and use the expression language. For example:
@Cacheable(pools="products" key="'product::hasProduct-' ~ productCode")
  • Create your own KeyGenerator. Note that if you do this, you will only have access to the method arguments as described in the section above.

So to conclude: your problem doesn't have anything to do with redis nor PSR-6. It's just one of the downfalls of the current key generator.

I hope both the problam and solution are clear to you now.

from annotated-cache.

veewee avatar veewee commented on June 14, 2024

I've changed the KeyGeneratorInterface and tagged the changes as: v0.2.0
By default it will use the classname and method name in the SimpleKeyGenerator. This means you won't have to add any key option to your annotations as described above.

from annotated-cache.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.