95992828九五至尊2

882828九五至尊手机版达成八个档次的缓存共享,小编的架构截图

三月 15th, 2019  |  882828九五至尊手机版

aop_cache项指标架构

 

aop_cache项目标架构,主要完结前台项目与后台项目共用缓存,缓存使用
Microsoft.Practices.EnterpriseLibrary.Caching,采取方法性子的注入,将急需缓存的办法进行拦阻,AOP
功能选拔Microsoft.Practices.Unity.Interception实行落到实处,缓存的中间件采取WCF实现,所以供给缓存的地方都通
过WCF去与Infrastructure.Core进行互动来取多少,WEB层只与WCF通讯,若是不需求缓存的地方,WEB层能够一直访问
Infrastructure.Core层。

Domain.Core:与实业相关,与O奥迪Q5M架构非亲非故,包罗实体规约,实体集合分页,实体验证等

Infrastructure.Core:实现多少的持久化,与OQashqaiM架构有关,近年来它只提供了EF进行持久化到SQLSEHavalVE奥迪Q5;现在能够提供其他持久化的措施。

Web.Core:前台WEB应用相关,包罗了用户音信持久化(cookies,session),文件上传相关,分页体现相关等。

882828九五至尊手机版 1

重返目录

Common.Background项指标架构

Common.Background项目重点作用是三个通用的后台管理种类的框架结构,方便以往别的类型的后台管理连串的成立,它就像叁个插件,能够方便的配备到各类系统之上。

882828九五至尊手机版 2

政工是如此的,前台网站某个数据不期待每便都从数据Curry读,所以,应该做个缓存,而引起缓存更新的入口来自网站的后台管理,而前台和后台被安顿在不一致的网站中,那时缓存的换代就成了难题,前台的缓存与后台的操作不可能联系到联合,为了消除这些标题,作者引入了WCF作为中间件,所以与数据库的操作,读,写都出自三个输入,这正是WCF,WCF用户告知你是还是不是从缓存取数据,全数缓存的数额也缓存在WCF中,OK,想法不错,上面包车型地铁话一下实际的贯彻步骤。

Tsingda.Tools项目标架构

Tsingda.Tools项目利用Thrift作为通信基础,使用Unity完毕IoC和AOP,使用entityframeworks达成数据的持久化,使用window
service作客户端,使用winform作服务端。

882828九五至尊手机版 3

一 首先看一下组织图:

882828九五至尊手机版 4

留神看作者的结构图,前台aop_cache和后台aop_cache_background项目都引用aop_cache_webservice项目,而它们没有对数据层aop_cache_data的引用,这个aop_cache_webservice是2个WCF项目,首要达成与数据层的通信工作,当然也能够与BLL业务层通信,那个框架结构首若是讲怎样促成前后台共享缓存,而不要讲架构,所以首要不再框架结构,而在达成共享缓存。


WCF层落成所要求的DLL,主若是unity,cache,interception,log4net等,如图:

882828九五至尊手机版 5

三 对于unity,wcf,cache的调用上,作者举办了三次封装,如图:

882828九五至尊手机版 6

四 看了那些,我们再来看一下,WEB层调用WCF层的代码片断:

        public ActionResult Index()
        {
            //  通过WCF获取远程数据,不走缓存, 走config中的<system.serviceModel>
            using (ServiceProxy<IService1> proxy = new ServiceProxy<IService1>())
            {
                return View(proxy.Channel.GetClassroom_Info());
            }
        }

web层的安插文件包括了对WCF的调用

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="ServiceProxyBinding" sendTimeout="00:10:00" receiveTimeout="00:10:00" closeTimeout="00:10:00"></binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint name="IService1" address="http://www.aop.com/Service1.svc" contract="aop_cache_WebService.IService1" binding="basicHttpBinding" bindingConfiguration="ServiceProxyBinding" />
    </client>
  </system.serviceModel>

 


WCF层调用DAL层的代码,使用unity来做方法阻碍与依靠注入,将cache功用注入到钦赐方法中

        IClassroom_InfoRepository _iClassroom_InfoRepository = ServiceLocator.Instance.GetService<IClassroom_InfoRepository>();
        public void InsertClassroom_Info(Classroom_Info entity)
        {
            _iClassroom_InfoRepository.InsertClassroom_InfoData(entity);
        }

        public List<Classroom_Info> GetClassroom_Info()
        {
            return _iClassroom_InfoRepository.GetClassroom_InfoData();
        }


对于WCF的铺排文件,大家要注重看一下,它富含了数据库连接串的安插和unity的布署

  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

    <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" />
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    <section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <connectionStrings>
    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-aop_cache-20131030092430;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-aop_cache-20131030092430.mdf" />
    <add name="TsingDa_NewLearningBarEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=TsingDa_NewLearningBar;user id=sa;password=zzl123;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

  <!--BEGIN: Unity-->
  <unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    <sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Microsoft.Practices.Unity.Interception.Configuration" />
    <container>
      <extension type="Interception" />
      <register type="Project.Caching.ICacheProvider,  Project.Caching" mapTo="Project.Caching.EntLibCacheProvider,  Project.Caching" />
      <!--对WCF的访问进行的注入与缓存和异常的拦截-->
      <register type="aop_cache_Data.IClassroom_InfoRepository, aop_cache_Data" mapTo="aop_cache_Data.Classroom_InfoRepository, aop_cache_Data">
        <interceptor type="InterfaceInterceptor" />
        <interceptionBehavior type="Project.InterceptionBehaviors.CachingBehavior, Project.InterceptionBehaviors" />
      </register>
    </container>
  </unity>
  <!--END: Unity-->
  <!--BEGIN: Caching-->
  <cachingConfiguration defaultCacheManager="ByteartRetailCacheManager">
    <cacheManagers>
      <add name="ByteartRetailCacheManager" type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" expirationPollFrequencyInSeconds="600" maximumElementsInCacheBeforeScavenging="1000" numberToRemoveWhenScavenging="10" backingStoreName="NullBackingStore" />
      <!--
          expirationPollFrequencyInSeconds:过期时间(seconds)
          maximumElementsInCacheBeforeScavenging:缓冲中的最大元素数量
          numberToRemoveWhenScavenging:一次移除的数量
      -->
    </cacheManagers>
    <backingStores>
      <add type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="NullBackingStore" />
    </backingStores>
  </cachingConfiguration>
  <!--END: Caching-->

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Practices.Unity.Interception" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
<system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Warning" propagateActivity="true">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="d:\wcf.svclog" />
    </sharedListeners>
  </system.diagnostics>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

 


DAL层的落到实处,由接口和落到实处两局地构成,接口的不二法门上分明了是不是要开始展览cache操作

   public interface IClassroom_InfoRepository
    {
        [Caching(CachingMethod.Remove, "GetClassroom_InfoData")]
        void InsertClassroom_InfoData(Classroom_Info entity);
        [Caching(CachingMethod.Get)]
        List<Classroom_Info> GetClassroom_InfoData();
    }

兑现很简单,只是五个测试而以

   public class Classroom_InfoRepository : TsingDa_NewLearningBarRepository<Classroom_Info>, IClassroom_InfoRepository
    {
        public void InsertClassroom_InfoData(Classroom_Info entity)
        {
            base.Insert(entity);
        }
        public List<Classroom_Info> GetClassroom_InfoData()
        {
            return base.GetModel().ToList();
        }
    }

 回去目录

Your Comments

近期评论

    功能


    网站地图xml地图