刹那的菜鸟

博客园 首页 新随笔 联系 管理

引用 Microsoft.Extensions.Caching.SqlServer 可以设置存在数据库

Microsoft.Extensions.Caching.Redis 存在redis

参考 

http://www.cnblogs.com/hantianwei/p/5723959.html

 

// Microsoft SQL Server implementation of IDistributedCache.
// Note that this would require setting up the session state database.
services.AddDistributedSqlServerCache(o =>
{
o.ConnectionString = "Server=.;Database=ASPNET5SessionState;Trusted_Connection=True;";
o.SchemaName = "dbo";
o.TableName = "Sessions";
});

数据库表 结构:

CREATE TABLE [dbo].[CacheTable](
    [Id] [nvarchar](449) NOT NULL,
    [Value] [varbinary](max) NOT NULL,
    [ExpiresAtTime] [datetimeoffset](7) NOT NULL,
    [SlidingExpirationInSeconds] [bigint] NULL,
    [AbsoluteExpiration] [datetimeoffset](7) NULL,
 CONSTRAINT [pk_Id] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
 
      
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
 
      
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON
[PRIMARY]

CREATE NONCLUSTERED INDEX [Index_ExpiresAtTime] ON [dbo].[CacheTable]
(
    [ExpiresAtTime] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
 
      
SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF,
 
      
ONLINE = OFF, ALLOW_ROW_LOCKS = ON,
 
      
ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

参考: http://gunnarpeipman.com/2017/04/aspnet-core-sql-server-cache/

老外还是很靠谱
posted on 2017-09-17 22:25  刹那的菜鸟  阅读(525)  评论(0编辑  收藏  举报