SSM 是如何生存Key的?

本文解析了Memcached中键的生成方法,通过KeyProvider接口的generateKey方法创建用于存储的键值。此外还介绍了如何根据CacheMethod返回值、斜线及命名空间构建完整的缓存键。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

源码中有一个接口:KeyProvider的 方法 String generateKey(final Object keyObject);

 

/**
     * From the supplied object, create a (no-whitespace) part of the key by which a value will be stored in Memcached.
     * (Hint: This value, plus the Namespace value, plus optional other key should be no longer than 250 characters.)
     * 
     * @param keyObject
     * @return
     */
    String generateKey(final Object keyObject);

 

 

根据CacheMethod 返回的值,已经斜线,命名空间生成key

private String buildCacheKey(final String[] objectIds, final String namespace) {
        if (objectIds.length == 1) {
            checkKeyPart(objectIds[0]);
            return namespace + SEPARATOR + objectIds[0];
        }

        StringBuilder cacheKey = new StringBuilder(namespace);
        cacheKey.append(SEPARATOR);
        for (String id : objectIds) {
            checkKeyPart(id);
            cacheKey.append(id);
            cacheKey.append(ID_SEPARATOR);
        }

        cacheKey.deleteCharAt(cacheKey.length() - 1);
        return cacheKey.toString();
    }

转载于:https://www.cnblogs.com/pan2011/p/3650302.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值