缓存清理(Python实现)原创
4人赞赏了该文章
3,277次浏览
编辑于2022年06月16日 18:10:46
参考社区知识:【二开案例.单据插件.缓存清理】,用Python实现,供参考
import clr clr.AddReference("mscorlib") clr.AddReference('System') clr.AddReference('System.Data') clr.AddReference('Kingdee.BOS') clr.AddReference('Kingdee.BOS.Core') clr.AddReference('Kingdee.BOS.App.Core') clr.AddReference('Kingdee.BOS.App') clr.AddReference('Kingdee.BOS.DataEntity') clr.AddReference('Kingdee.BOS.ServiceHelper') clr.AddReference('Kingdee.BOS.Contracts') clr.AddReference('Kingdee.K3.Core') from System import * from System.Data import * from System.Collections import * from System.Collections.Generic import * from System import StringComparison from Kingdee.BOS.Log import Logger from Kingdee.BOS import * from Kingdee.BOS.Util import * from Kingdee.BOS.App.Core import * from Kingdee.BOS.App.Data import * from Kingdee.BOS.Core.Bill.PlugIn import * from Kingdee.BOS.Core.Const import * from Kingdee.BOS.ServiceHelper import * from Kingdee.BOS.Core.DynamicForm.PlugIn.Args import * def BarItemClick(e): if e.BarItemKey.Equals("tbButton_1", StringComparison.OrdinalIgnoreCase): formIds = List[object]() formIds.Add("BD_MATERIAL") ClearCacheByFormIds(this.Context, formIds) this.View.ShowMessage("物料的缓存已被清空!") if e.BarItemKey.Equals("tbButton_2", StringComparison.OrdinalIgnoreCase): materialIds = List[String]() materialIds.Add("139886") materialIds.Add("139892") ClearCacheByPrimaryKeys(this.Context, "BD_MATERIAL", materialIds) this.View.ShowMessage("物料【XXX】的缓存已被清空!") def ClearCacheByFormIds(ctx, formIds): if formIds == None or len(formIds) == 0: return False area = ctx.GetAreaCacheKey() for formId in formIds: metadata = FormMetaDataCache.GetCachedFormMetaData(ctx, formId) if metadata != None: CacheUtil.ClearCache(area, metadata.BusinessInfo.GetEntity(0).TableName) CacheUtil.ClearCache(ctx.DBId + formId, CacheRegionConst.BOS_QuickBaseDataCache) return True def ClearCacheByPrimaryKeys(ctx, formId, keys): if keys == None or len(keys) == 0: return False metadata = FormMetaDataCache.GetCachedFormMetaData(ctx, formId) if metadata == None: return False cacheManager = DataEntityCacheManager(ctx, metadata.BusinessInfo.GetDynamicObjectType()) cacheManager.RemoveCacheByPrimaryKeys(keys) CacheUtil.ClearCache(ctx.DBId + formId, CacheRegionConst.BOS_QuickBaseDataCache) return True
一、注意:
1、实际测试,在不同账套环境出现:清理缓存(整个基础资料的缓存全清)- ClearCacheByFormIds(Context ctx, List<string> formIds) 这个方法没有效果,即根据基础资料FormId清除对应缓存没有生效。
2、通过id来清除基础资料,即:ClearCacheByPrimaryKeys(Context ctx, string formId, List<string> keys) 正常生效。
二、参考
【二开案例.表单插件.缓存清理(按区段清理)】
缓存清理(Python实现).rar(0.90KB)
赞 4
4人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!