Database component Hxj.data (22) (cache)

Source: Internet
Author: User

First of all, I do web development, so many will favor the Web, components use the cache is System.Web.HttpRuntime.Cache.

The component is off the cache by default.

So to open the cache query to do the configuration.

Let's take a look at the example configuration:

<configSections>
   <section name="HxjCacheConfig" type="Hxj.Data.CacheConfiguration,Hxj.Data"/>
</configSections>
<HxjCacheConfig enable="true">
   <entities>
     <add key="NorthwindConnectionString.Products" value="60"></add>
   </entities>
</HxjCacheConfig>
<connectionStrings>
   <add name="NorthwindConnectionString" connectionString="Data Source=ricci\hu;Initial  Catalog=Northwind;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

The Hxjcacheconfig node's enable indicates whether the cache is turned on, and the default is off, unless enable= "true" is explicitly turned on.

The configuration under the Entities node is the cache configuration for entity queries.

<add key= "northwindconnectionstring.products" value= "></add>"

Represents the Products table configuration under the connection of the node Name= "NorthwindConnectionString" in connectionstrings.

Value= "60" indicates a cache of 60 seconds.

So be sure to connectionstrings the name plus the entity name, otherwise the configuration is invalid.

Of course, value can also be a cached dependent file.

<add key="NorthwindConnectionString.Products"  value="1.txt"></add>

Represents a 1.txt file under the root directory of the query cache dependencies for the Products table. component determines whether the file exists or does not exist, the configuration is invalid.

Then test the cache configuration.

List<Products> list = new List<Products>();
for (int i = 0; i < 2; i++)
{
   list.Add(DbSession.Default.From<Products>().ToFirst());
}

for (int i = 0; i < 3; i++)
{
   list.Add(DbSession.Default.From<Products>().ToFirst());
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.