コード例 #1
0
        private static InkeyResult <string> GetMemcachedResult(string actionType, string sType, string vType, string cacheResult, FormatObjcet formart, List <string> pValueList)
        {
            InkeyResult <string> result = new InkeyResult <string>();
            var cacheManager            = new MemcachedManager(new CacheManagerActionCacheKeyFormat());
            var flag = false;

            switch (actionType)
            {
            case "View":
                object value = string.Empty;
                flag = cacheManager.RawIsSet(formart.Key, out value, pValueList.ToArray());
                if (!flag)
                {
                    result.Code = InkeyErrorCodes.CommonBusinessFailure;
                    result.Desc = "未设置缓存值";
                    return(result);
                }
                else
                {
                    result.Data = value is string?(string)value : value.ToJsonString();
                }
                break;

            case "Update":
                if (cacheManager.RawIsSet(formart.Key, out value, pValueList.ToArray()) && !(value is string))
                {
                    value = JsonConvert.DeserializeObject(cacheResult, value.GetType());
                    flag  = cacheManager.RawSet(formart.Key, value, pValueList.ToArray());
                }
                else
                {
                    flag = cacheManager.RawSet(formart.Key, cacheResult, pValueList.ToArray());
                }
                if (!flag)
                {
                    result.Code = InkeyErrorCodes.CommonBusinessFailure;
                    result.Desc = "请输入JSON";
                    return(result);
                }
                else
                {
                    result.Code = InkeyErrorCodes.CommonBusinessFailure;    //前端需要弹出提示,所有设置这个值
                    result.Desc = "更新成功";
                }
                break;

            case "Delete":
                flag = cacheManager.Remove(formart.Key, pValueList.ToArray());
                if (!flag)
                {
                    result.Code = InkeyErrorCodes.CommonBusinessFailure;
                    result.Desc = "缓存移除失败";
                    return(result);
                }
                break;
            }
            return(result);
        }
コード例 #2
0
        public bool IsAuthenticate(string token, out IdentityInfo identityInfo)
        {
            identityInfo = null;
            string cacheString;

            if (cacheManager.RawIsSet(_cache_distribute_token_key, out cacheString, token))
            {
                if (this._identityInfoType == null)
                {
                    this._identityInfoType = CreateIdentityInfo().GetType();
                }
                identityInfo = (IdentityInfo)JsonSerializerManager.JsonDeserialize(cacheString, this._identityInfoType);
                string touchValue;
                if (!cacheManager.RawIsSet(_cache_distribute_token_touch_key, out touchValue, token))
                {
                    cacheManager.RawSet(_cache_distribute_token_key, cacheString, _identity_distribute_expire_minutes, token);
                    cacheManager.Set(_cache_distribute_token_touch_key, 1, _identity_distribute_expire_minutes - 5, token);
                }
                return(true);
            }
            return(false);
        }