Enable your framework to implement the cache Function

Source: Internet
Author: User

In the process of stripping, I removed most of the backingstoreimplementations, except all of the instrumentation <used for logs and counters>, except that the configuration file must be used.
The current function can only rely on memory for caching. Modifying constants affects cache behavior.
However, without relying on the configuration file, you can easily integrate your own framework.
Because there was no time to test the migration yesterday Code , So no code is released
Currently, only the absoultetime slidingtime neverexpire method is supported. For filedependency, You need to integrate an action by yourself. Therefore, you have not performed any tests and have not studied whether the transplanted code is feasible.
Http://files.cnblogs.com/wildfish/Caching.rar
I tested it today and thought it was okay.
By the way, the test code is released. Using System;
Using System. Data;
Using Nunit. Framework;
Using Fishsky. systemframework. caching;
Using Fishsky. systemframework. caching. expirations;
Using Fishsky. systemframework. base;
Using Fishsky. Data. base;
Using System. Threading;
Namespace Fishskytest. systemframeworktest
{
/**/ /// <Summary>
///A summary of cachingtesting.
/// </Summary>
[Testfixture]
Public   Class Cachingtesting
{
Private Cachemanager Manager = Cachefactory. getcachemanager ();
Private   Static   String Keywordtostore1 = " Keywordtostore1 " ;
Private   Static   String Keywordtostore2 = " Keywordtostore2 " ;
Private   Static   String Keywordtostore3 = " Keywordtostore3 " ;
Private   Static   String Keywordtostore4 = " Keywordtostore4 " ;

Public Cachingtesting ()
{

}

Setup # Region Setup

[Setup]
Public   Void Setup ()
{
Manager. Flush ();
}

# Endregion

Testtimespancacheaddremove # Region Testtimespancacheaddremove

[Test]
Public   Void Testtimespancacheaddremove ()
{
Console. writeline ( " Testing start. " );

Wherefield Wf = New Wherefield ( " Penavicoxm " , Typeof ( String ), 20 , True , False );
WF. fieldvalue = " Kevin " ;

Setfield SF = New Setfield ( " Penavicoxmset " , Typeof ( String ), 30 , False );
SF. fieldvalue = " Kevin. Chin " ;



Timespan timespan1 = New Timespan ( 0 , 10 , 0 );
Timespan timespan2 = New Timespan ( 0 , 0 , 20 );



Slidingtime expiretime1 = New Slidingtime (timespan1 );
Slidingtime expiretime2 = New Slidingtime (timespan2 );


Manager. Add (cachingtesting. keywordtostore1, WF, cacheitempriority. Normal, Null , Expiretime1 );
Manager. Add (cachingtesting. keywordtostore2, SF, cacheitempriority. Normal, Null , Expiretime2 );


Wherefield cachedwf = Manager. getdata (cachingtesting. keywordtostore1) As Wherefield;
Assert. isnotnull (cachedwf );
Assert. areequal (cachedwf. fieldvalue. tostring (), " Kevin " );

Manager. Remove (cachingtesting. keywordtostore1 );


Object OBJ = Manager. getdata (cachingtesting. keywordtostore1 );
Assert. isnull (OBJ );

Console. writeline ( " Testing will sleep 180 seconds. " );

Thread. Sleep ( 180000 );

Object Nullcache2 = Manager. getdata (cachingtesting. keywordtostore2 );
Assert. isnull (nullcache2 );

Console. writeline ( " Testing finished! " );
}

# Endregion

Testabsolutetime # Region Testabsolutetime

[Test]
Public   Void Testabsolutetime ()
{
Setfield sf2 = New Setfield ( " Penavicoxmset " , Typeof ( String ), 30 , False );
Sf2.fieldvalue = " Kevin. Chin " ;

// Each time u wanna test, must change the time to one minute before the test
Datetime refreshdatetime = New Datetime ( 2006 , 1 , 12 , 10 , 41 , 20 );
Absolutetime expiretime3 = New Absolutetime (refreshdatetime );

Manager. Add (cachingtesting. keywordtostore3, sf2, cacheitempriority. Normal, Null , Expiretime3 );

Assert. isnotnull (Manager. getdata (cachingtesting. keywordtostore3 ));
Thread. Sleep ( 120000 );
Assert. isnull (Manager. getdata (cachingtesting. keywordtostore3 ));

}

# Endregion

Testneverexpired # Region Testneverexpired

[Test]
Public   Void Testneverexpired ()
{
Setfield sf2 = New Setfield ( " Penavicoxmset " , Typeof ( String ), 30 , False );
Sf2.fieldvalue = " Kevin. Chin " ;

Manager. Add (cachingtesting. keywordtostore4, sf2, cacheitempriority. Normal, Null , Null );

Assert. isnotnull (Manager. getdata (cachingtesting. keywordtostore4 ));

Thread. Sleep ( 120000 );

Assert. isnotnull (Manager. getdata (cachingtesting. keywordtostore4 ));

}

# Endregion
}
}

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.