,
脚本中
HeadCache: function () {
var loadIndex = showLoading()
var actHeadMessage = $("#act_head_form").serializeJson();
actHeadMessage.convert_grossWt = actHeadMessage.grossWt;
actHeadMessage.convert_netWt = actHeadMessage.netWt;
$.ajax({
type: "POST",
url: 'HeadCache',
data: actHeadMessage,
contentType: "application/x-www-form-urlencoded",
dataType: "json",
beforeSend: function () {
$("#headSave").attr("disabled", "disabled");
},
success: function (data) {
if (data.Success) {
if (data.Message) {
layerMsg("保存成功!" + data.Message, 1);
} else {
layerMsg("保存成功!", 1);
}
data.Data.iEDate = DateFormatterForIeDare(data.Data.iEDate)
$("#act_head_form").setForm(data.Data)
inner_no = data.Data.innerNo
if ($("#REF_19_H").val() != "") {
if ($("#REF_19_H").val() == "FCL") {
$("#ACTUAL_BOX_NAME_attr").css('display', 'block');
}
else if ($("#REF_19_H").val() == "LCL") {
$("#ACTUAL_BOX_NAME_attr").css('display', 'none');
}
}
} else {
showLayerAlert("保存失败!" + data.Message);
}
},
error: function (data) {
layerMsg("保存失败!" + data.Message, 2);
},
complete: function () {
hideLoading(loadIndex);
$("#headSave").removeAttr("disabled");;
}
});
}
[HttpPost]
[AccessLogAttribute("台账表头缓存")]
public ActionResult HeadCache(ActHeadDevMap model)
{
CommonResult
StringBuilder key = new StringBuilder();
key.Append(_appUser.UserId + _appUser.CurrentCorpInfo.Site + model.innerNo+model.iEFlag);
if (string.IsNullOrWhiteSpace(model.innerNo))
{
key.Append("ACT_HEAD_C");
}
else
{
key.Append("ACT_HEAD_E");
}
SaveRedisByKey(key.ToString(),model);
result.Data = model;
result.Success = true;
return Json(result);
}
///
/// 存入缓存
///
///
///
///
public void SaveRedisByKey
{
RedisHepler redisHepler = new RedisHepler("127.0.0.1:6379");
string content = JsonConvert.SerializeObject(t);
redisHepler.SetValue(key,content);
}
///
/// 根据KEY获取缓存数据
///
///
///
///
public T GetRedisByKey
{
RedisHepler redisHepler = new RedisHepler("127.0.0.1:6379");
string content = redisHepler.GetValue(key);
T model= JsonConvert.DeserializeObject
return model;
}
----------------
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Longnows.Saas.PG.UI.Model
{
public class RedisHepler
{
private ConnectionMultiplexer redis { get; set; }
private IDatabase db { get; set; }
public RedisHepler(string connection)
{
redis = ConnectionMultiplexer.Connect(connection);
db = redis.GetDatabase();
}
///
/// 增加/修改
///
///
///
///
public bool SetValue(string key, string value)
{
return db.StringSet(key, value);
}
///
/// 查询
///
///
///
public string GetValue(string key)
{
return db.StringGet(key);
}
///
/// 删除
///
///
///
public bool DeleteKey(string key)
{
return db.KeyDelete(key);
}
public bool IsExitKey(string key)
{
return db.KeyExists(key);
}
}
}