NET Caching Library Help
Flush Method (SmartCache)
Example 




KellermanSoftware.NetCachingLibrary Namespace > SmartCache Class : Flush Method
Number of seconds to wait to flush
Wait until queued items are written from the secondary cache
Syntax
'Declaration
 
Public Sub Flush( _
   ByVal seconds As System.Integer _
) 
'Usage
 
Dim instance As SmartCache
Dim seconds As System.Integer
 
instance.Flush(seconds)
public void Flush( 
   System.int seconds
)
public: void Flush( 
   System.int seconds
) 
public:
void Flush( 
   System.int seconds
) 

Parameters

seconds
Number of seconds to wait to flush
Example
//Create a file cache with async set and remove
string directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "KellermanSoftware", "NetCachingLibrary", "Tests");
FileCacheProvider fileCacheProvider = new FileCacheProvider(directory);
fileCacheProvider.IsAsyncSetAndRemove = true;
 
SmartConfig config = new SmartConfig(new MemoryCacheProvider(), fileCacheProvider);
 
//Specify UserName and LicenseKey for Licensed Mode
//config.UserName = "my user name";
//config.LicenseKey = "my license key";
 
//Instantiate the cache
SmartCache cache = new SmartCache(config);
 
//Save 12 months asynchronously
for(int i = 1; i <= 12;i++)
{
    string cacheKey = string.Format("FlushTest-{0}", i);
 
    //Get a long running report
    List<ReportDetail> report = ReportLogic.MonthlySalesReport(i, DateTime.Now.Year - 1);
 
    //Save to the cache asynchronously
    cache.Set<List<ReportDetail>>(cacheKey, report);
}
 
//Flush the cache
cache.Flush(5);
 
//This will be false since we flushed
Console.WriteLine(cache.IsBusy);
'Create a file cache with async set and remove
Dim directory As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "KellermanSoftware", "NetCachingLibrary", "Tests")
Dim fileCacheProvider As New FileCacheProvider(directory)
fileCacheProvider.IsAsyncSetAndRemove = True
 
Dim config As New SmartConfig(New MemoryCacheProvider(), fileCacheProvider)
 
'Specify UserName and LicenseKey for Licensed Mode
'config.UserName = "my user name";
'config.LicenseKey = "my license key";
 
'Instantiate the cache
Dim cache As New SmartCache(config)
 
'Save 12 months asynchronously
For i As Integer = 1 To 12
    Dim cacheKey As String = String.Format("FlushTest-{0}", i)
 
    'Get a long running report
    Dim report As List(Of ReportDetail) = ReportLogic.MonthlySalesReport(i, Date.Now.Year - 1)
 
    'Save to the cache asynchronously
    cache.Set(Of List(Of ReportDetail))(cacheKey, report)
Next i
 
'Flush the cache
cache.Flush(5)
 
'This will be false since we flushed
Console.WriteLine(cache.IsBusy)
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

SmartCache Class
SmartCache Members