Skip to content

Incorrect Cache Key Generation when (hidden) static methods are used #35667

@fibsifan

Description

@fibsifan

Hello,

When static methods are used for cache key creation and 2 static methods have the same signature in a class inheritance hierarchy, then only one static method is used for cache key generation. I created a small example project: https://github.com/fibsifan/spring-cache-error

The most relevant part is in the Controller:

    @Cacheable(cacheNames = "cachedController", key = "T(de.jball.spring.caching.keys.ParentCacheKeyGenerator).getCacheKey()")
    @GetMapping("parent")
    public String getResponseWithParentCacheKey() {
        return "ResponseWithParentCacheKey";
    }

    @Cacheable(cacheNames = "cachedController", key = "T(de.jball.spring.caching.keys.ChildCacheKeyGenerator).getCacheKey()")
    @GetMapping("child")
    public String getResponseWithChildCacheKey() {
        return "ResponseWithChildCacheKey";
    }

If GET http://localhost:8080/parent is called first, then calls to /child always return ResponseWithParentCacheKey and vice versa.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions