All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sdl.dxa.caching.LocalizationAwareKeyGenerator Maven / Gradle / Ivy

Go to download

DXA Common project contains framework common classes shared between all other artifacts

There is a newer version: 2.3.7
Show newest version
package com.sdl.dxa.caching;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.cache.interceptor.SimpleKey;
import org.springframework.cache.interceptor.SimpleKeyGenerator;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.lang.reflect.Method;

/**
 * Default implementation of localization-aware cache key generator.
 *
 */
@Component
public class LocalizationAwareKeyGenerator implements KeyGenerator {

    @Autowired
    private LocalizationIdProvider localizationIdProvider;

    @Override
    public LocalizationAwareCacheKey generate(Object target, Method method, Object... params) {
        Object key = SimpleKeyGenerator.generateKey(params);
        return new LocalizationAwareCacheKey(localizationIdProvider.getId(), params.length == 1 ? new SimpleKey(key) : (Serializable) key);
    }

    public LocalizationAwareCacheKey generate(Object... params) {
        return generate(null, null, params);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy