zoukankan      html  css  js  c++  java
  • 【OF框架】缓存Session/Cookies/Cache代码调用api,切换缓存到Redis

    准备


    缓存服务在应用开发中最常用的功能,特别是Session和Cookies,Cache部分业务开发过程会使用到。

    在负载均衡环境下,缓存服务需要存储到服务器。

    缓存默认实现在内存在,可以通过配置切换到Redis服务。

    一、Session操作api


                //设置Session值
                SessionHelper.Set(key, value);
                //读取Session值
                var value = SessionHelper.Get(key);

    二、Cookies操作api


                //设置Cookie值
                CookieHelper.Set(key, value);
                //读取Cookie值
                var value = CookieHelper.Get(key);

    三、Cache操作api


                //设置Cache值
                CacheHelper.Set(key, value);
                //读取Cache值
                var value = CacheHelper.Get(key);

    四、切换缓存使用Redis


    第一步:安装运行Redis服务,获得连接参数。

    第二步:在appsettings.json中配置 EnableRedisCache 和 RedisconnectionString 连接字符串。false值时,默认使用Memory。

    {
      "EnableRedisCache": "true",
      "ConnectionStrings": {
        "RedisConnectionString": "redis.chenyinxin.com:3101"
      }
    } 

    切换后,Session、Cache的数据会写入到Redis中。

  • 相关阅读:
    122. Best Time to Buy and Sell Stock II
    121. Best Time to Buy and Sell Stock
    72. Edit Distance
    583. Delete Operation for Two Strings
    582. Kill Process
    indexDB基本用法
    浏览器的渲染原理
    js实现txt/excel文件下载
    git 常用命令
    nginx进入 配置目录时
  • 原文地址:https://www.cnblogs.com/chenyinxin/p/10870454.html
Copyright © 2011-2022 走看看