最新文章 (全部类别)
DevExpress GridView表格编辑模式下:RepositoryItemCheckEdit点击单元格立即勾选
LookupEdit 输入内容自动定位搜索和匹配内容
FastReport.NET导出Excel参数配置
自动部署SSL证书 Certify The Web / Certify SSL/TLS Certificate Management
CSFramework WebApi 极速版后端开发框架(.NET8+EF.Core+多数据库支持)
FastReport.NET2023破解版去除水印DEMO VERSION (2025.1.14/2023.2.18版本)
CSFrameworkV6旗舰版-单据窗体明细表格图片处理
DevExpress LookupEdit按回车键自动确认选择数据
金罗门ERP - 用户操作手册 - 我的任务
SqlConnectorV6.1 - 数据库连接工具
CSFrameworkV6 试用版(Trial Version)开发指南
C# 使用ImageConverter Image转Byte数组
毛衫行业ERP系统 - 考勤报表
CSFramework开发框架选型推荐
PostgresException: 22001: 对于可变字符类型来说,值太长了(1)
CSFrameworkV6删除全部Demo功能整合一套纯净版开发框架
电脑设置接通电源自动开机BIOS设置开启WOL唤醒功能
CSFrameworkV6旗舰版合并数据库解决方案 (CSFrameworkV6_All)
CSFramework WebApi框架极速版与商业版功能差异与性能对比
CSFramework.Workflow - 可视化工作流引擎 - 用户开发指南
CSFramework.Workflow - 工作流程引擎测试程序(Demo演示版)
CSFramework.Workflow - 可视化工作流引擎 - 业务系统集成解决方案
C/S开发框架:系统数据库与账套数据库合并解决方案(SqlServer版本)
DevExpress GridView Master/Detail主子表格刷新子表数据源
CSFrameworkV6旗舰版 - 还原数据&还原数据日志
通用选择记录窗体
CSFramework.WebApiV3.WebApi快速开发指南
C/S快速开发框架旗舰版CSFrameworkV6.0 - VS开发环境配置
PostgreSql数据库常用操作 - 使用Bat批处理脚本还原数据库
C/S架构自动升级程序 - .NET8版本最新优化
CSFramework WebApi开发框架集成PostgreSql数据库及测试报告
WebApi开发框架接口模版代码
CSFramework.WebApi框架 - 使用并发控制过滤器 RequestConcurrentAttribute
CSFramework.Workflow - 可视化工作流引擎 - 条件审批操作手册
VS2022.NET8 + PostgreSql 数据库使用入门指南
CSFrameworkV6快速开发框架 - 使用PostgreSql 数据库测试报告
CSFrameworkV6快速开发框架 - 使用 SqlConnector 连接 PostgreSql 数据库测试报告
CSFrameworkV6快速开发框架 - 使用代码生成器连接 PostgreSql 数据库测试报告
CSFramework.EF.PostgreSql数据库组件 PostgreSql数据库测试报告
CSFramework.EF数据库框架简介(.NET8+EFCore)
PostgreSql数据库常用操作 - 使用Bat批处理脚本备份所有数据库
DevExpress DateEdit组件显示和编辑日期和时间
PostgreSQL 更新数据库所有表的字段类型 timestamp 类型改为 timestamptz
C#获取MAC地址包括物理网卡和虚拟网卡
塑木地板行业ERP-公共字典数据操作手册
主程序添加数据库引用Nuget安装包
金罗门ERP - 用户操作手册 - 库存盘点操作手册
塑木地板行业ERP-预收款核销操作手册
.NET8 .NETCore运行环境下载
金罗门ERP - 用户操作手册 - BOM基础资料
.net敏捷开发,创造卓越

C#数据库本地缓存技术(Database local cache)


C#数据库本地缓存技术(Database local cache)


Database local cache

By konamiman34

A C# class that uses the local file system to cache binary objects stored in a database.

一个C#类用于存储数据库上的二进制对象(数据)保存为本地文件。

类的主要方法:

SaveObject:

As for the public methods exposed by the class, these are the ones:

  • SaveObject: Will store in the database the specified byte array or the contents of the specified file, with the specified name or with the same name as the file itself (there are three method overloads). If there is already an object with the same name in the database, its contents will be overwritten. This method does not access the local cache at all.
  • GetObject: Will retrieve an object from either the database or the local cache, following the algorithm explained above. Returns the path to the cached file, or null if the object with the specified name does not exist in the database.
  • GetCachedFile: Will return the path of the cached file for the specified object name, if it exists, or null otherwise, without accessing the database at all. This method can be used as a "life vest" if the database becomes unreachable, but only if it is acceptable to use data that may be out of date.
  • DeleteObject: Deletes the object with the specified name from both the database and the local cache, if it exists.
  • RenameObject: Changes the name of an object in both the database and the local cache, if it exists.
  • ObjectExists: Returns a boolean value indicating whether an object exists in the database with the specified name or not.
  • GetObjectNames: Returns an array of strings with the names of all the objects stored in the database.
  • PurgeCache: Deletes from the local cache all the files that have no matching object in the database. If the database is accessed by multiple users, it may be convenient to execute this method once when the application execution begins and/or ends.

Note that you can, at any time, manually delete some or all of the cached files, besides/instead of using the PurgeCache method. The class does not maintain any state information about the cached files, it only searches for existing files as needed.

Here are some simple examples of how to use the class. For example, for creating an instance, having the database table named Photos and using C:\PhotosCache as the cache directory, you would do:


SqlConnection connection=new SqlConnection(@"Data Source" +

     @"=.\SQLEXPRESS;AttachDbFilename="|DataDirectory" +

     @"|Data\MyDatabase.mdf";Integrated security=true;");

DatabaseFileCache cache=new DatabaseFileCache(connection, "Photos", @"C:\PhotosCache");



Then, to store objects in the database:


cache.SaveObject(@"C:\Photos\DSCF0100.jpg", "Kaito’s first birtday.jpg");

// Using an alternative method overload:

cache.SaveObject(new byte[] { 1, 3, 5, 7, 11 }, "Some primes");



And to retrieve the data:


string filePath=cache.GetObject("Kaito’s first birtday.jpg")

MyForm.MyPictureBox.Load(filePath);

 

filePath=cache.GetObject("Some primes");

byte[] somePrimes=File.ReadAllBytes(filePath);




原文:http://www.codeproject.com/KB/database/DatabaseLocalCache.aspx

www.csframework.com

版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
C/S框架网
上一篇:C#SQL客户端处理大文本数据通用接口
下一篇:异步实现Socket Server&Client
评论列表

发表评论

评论内容
昵称:
关联文章

C#数据库本地缓存技术(Database local cache)
C# 本地图片缓存器ImageFileCache (www.csframework.com)
MySqlConnector.MySqlException:“Loading local data is disabled
C/S框架日志管理管理器(LogUserOperate)/本地日志(LogLocalException)/数据库日志(LogDB)
DataDictCache - 全局缓存设计逻辑详解
C#根据本地IP获取MAC地址(Windows API SendARP函数方式)
C#获取本地的IP地址
EF问题:The model backing the 'GenericDbContext' context has changed since the database was created.
开发应用-观察者模式之C#实现缓存数据更新
本地文件日志,LocalLog.cs
C#读取Excel文件提示:未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”
解决方案:C#使用Process.Start调用默认程序打开本地文件
Entity Framework(EF)测试DbContext.Database.ExecuteSqlCommand方法删除记录
C# INI本地文件读写工具类IniFileTool.cs
C#.Net反射(Reflaction)技术实例详解
软件开发与设计 - 青牛(北京)软件技术有限公司-USE数据库设计
The Database principal owns a schema in the database
Nginx技术(2)Nginx配置文件简述
本地源“C:\Program Files\DevExpress 22.2\Components\System\Components\Packages”不存在
【原创】WebApi开发框架:Token生成、Token缓存原理、Token验证、令牌机制与原理

热门标签
软件著作权登记证书 .NET .NET Reactor .NET5 .NET6 .NET7 .NET8 .NET9 .NETFramework AI编程 APP AspNetCore AuthV3 Auth-软件授权注册系统 Axios B/S B/S开发框架 B/S框架 BSFramework Bug Bug记录 C#加密解密 C#源码 C/S CHATGPT CMS系统 CodeGenerator CSFramework.DB CSFramework.EF CSFramework.License CSFrameworkV1学习版 CSFrameworkV2标准版 CSFrameworkV3高级版 CSFrameworkV4企业版 CSFrameworkV5旗舰版 CSFrameworkV6.0 CSFrameworkV6.1 CSFrameworkV6旗舰版 DAL数据访问层 DaMeng Database datalock DbFramework DeepSeek Demo教学 Demo实例 Demo下载 DevExpress教程 Docker Desktop DOM ECS服务器 EFCore EF框架 Element-UI EntityFramework ERP ES6 Excel FastReport GIT HR IDatabase IIS JavaScript LINQ MES MiniFramework MIS MSSQL MySql NavBarControl NETCore Node.JS NPM OMS Oracle资料 ORM PaaS POS PostgreSql Promise API PSD QMS RedGet Redis RSA SAP Schema SEO SEO文章 SQL SQLConnector SQLite SqlServer Swagger TMS系统 Token令牌 VS2022 VSCode VS升级 VUE WCF WebApi WebApi NETCore WebApi框架 WEB开发框架 Windows服务 Winform 开发框架 Winform 开发平台 WinFramework Workflow工作流 Workflow流程引擎 XtraReport 安装环境 版本区别 报表 备份还原 踩坑日记 操作手册 达梦数据库 代码生成器 电子线材ERP 迭代开发记录 功能介绍 官方软件下载 国际化 基础资料窗体 架构设计 角色权限 开发sce 开发工具 开发技巧 开发教程 开发框架 开发平台 开发指南 客户案例 快速搭站系统 快速开发平台 框架升级 毛衫行业ERP 秘钥 密钥 权限设计 软件报价 软件测试报告 软件加壳 软件简介 软件开发框架 软件开发平台 软件开发文档 软件授权 软件授权注册系统 软件体系架构 软件下载 软件著作权登记证书 软著证书 三层架构 设计模式 生成代码 实用小技巧 视频下载 收钱音箱 数据锁 数据同步 塑木地板行业ERP 微信小程序 未解决问题 文档下载 喜鹊ERP 喜鹊软件 系统对接 详细设计说明书 新功能 信创 行政区域数据库 需求分析 疑难杂症 蝇量级框架 蝇量框架 用户管理 用户开发手册 用户控件 在线支付 纸箱ERP 智能语音收款机 自定义窗体 自定义组件 自动升级程序
联系我们
联系电话:13923396219(微信同号)
电子邮箱:23404761@qq.com
站长微信二维码
微信二维码