How to access cache in .Net 5

#1
Hi guys,

I am trying to use scaleout cache in a .Net 5 application an I am a bit confused.
Here's what I know so far by following the article:

https://static.scaleoutsoftware.com/docs/user_guide/installation/windows/steps.html


#1: Install package "Scaleout.AspNetCore"
#2: Add this section to the config file ( replacing with correct values)

"ScaleOutStateServer": {
"gateways": [
{
"ip": "10.0.0.100",
"servicePort": 721
},
{
"ip": "10.0.0.101",
"servicePort": 721
}
],
"defaultNamespace": "HelloWorld",
"protocol": "SossTcpTransport"
}



#3: Update ConfigureServices(IServiceCollection) as follows

{
// Add framework services.
// ...
services.AddSession();

// Add ScaleOut implementation of IDistributedCache.
services.AddScaleoutDistributedCache(Configuration);

// ...
}


From what I understand, from this point on all access to "HttpContext.Session" will use scaleout

Question:
1- How can I verify that the session is in fact using scaleout?
2- Is there a "Cache" that is separate from the "Session"? If so, how can I use it (a link or example would usefull)


Thanks in advance for any help.
 

markw

Administrator
Staff member
#2
Hi Amunike,

1. Your configuration looks good. Assuming you've installed the ScaleOut service on one or more hosts, open the ScaleOut Management Console application on one of the servers and check the store's object count--each new user session should cause the object count to increase by one.

Also, the ScaleOut Object Browser application is available with a Management Pack license: it allows you to view all the objects currently stored in the ScaleOut service.

2. Yes, there are caching APIs available for .NET 5.0: the Scaleout.Client library is available on NuGet here, with documentation available here--you'll find examples and configuration info in the "Articles" area.
 
#4
One last question markw,

In the context of a web application, should I run this code per request?

Code:
              // Connect to the ScaleOut service (in this case, one host running locally):
                var conn = await GridConnection.ConnectAsync("bootstrapGateways = ");

                // Configure and build a Cache instance:
                var builder = new CacheBuilder<string, string>("My cache", conn);
                builder.SetObjectTimeout(TimeSpan.FromMinutes(20), TimeoutType.Absolute);
                var cache = builder.Build();
 

markw

Administrator
Staff member
#5
No, that code should only be run once, typically at application startup. Once you have a Cache instance then it can be reused throughout the app.
 
Top