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());
}