|
1 |
| -using System; |
2 |
| -using System.Collections.Generic; |
3 |
| -using System.Linq; |
4 |
| -using System.Threading.Tasks; |
5 |
| -using Enyim.Caching; |
| 1 | +using Enyim.Caching.Configuration; |
6 | 2 | using Enyim.Caching.SampleWebApp.Models;
|
7 | 3 | using Enyim.Caching.SampleWebApp.Services;
|
8 | 4 | using Microsoft.AspNetCore.Mvc;
|
9 | 5 | using Microsoft.Extensions.Logging;
|
| 6 | +using Microsoft.Extensions.Options; |
| 7 | +using System.Linq; |
| 8 | +using System.Net; |
| 9 | +using System.Threading.Tasks; |
10 | 10 |
|
11 | 11 | namespace Enyim.Caching.SampleWebApp.Controllers
|
12 | 12 | {
|
13 | 13 | public class HomeController : Controller
|
14 | 14 | {
|
15 | 15 | private readonly IMemcachedClient _memcachedClient;
|
16 | 16 | private readonly IMemcachedClient _postbodyMemcachedClient;
|
| 17 | + private readonly MemcachedClientOptions options; |
17 | 18 | private readonly IBlogPostService _blogPostService;
|
18 | 19 | private readonly ILogger _logger;
|
19 | 20 | public static readonly string CacheKey = "blogposts-recent";
|
20 | 21 | public static readonly string PostbodyCacheKey = "postbody";
|
21 | 22 |
|
22 | 23 | public HomeController(
|
23 | 24 | IMemcachedClient memcachedClient,
|
| 25 | + IOptions<MemcachedClientOptions> optionsAccessor, |
24 | 26 | IMemcachedClient<PostBody> postbodyMemcachedClient,
|
25 | 27 | IBlogPostService blogPostService,
|
26 | 28 | ILoggerFactory loggerFactory)
|
27 | 29 | {
|
28 | 30 | _memcachedClient = memcachedClient;
|
| 31 | + options = optionsAccessor.Value; |
29 | 32 | _postbodyMemcachedClient = postbodyMemcachedClient;
|
30 | 33 | _blogPostService = blogPostService;
|
31 | 34 | _logger = loggerFactory.CreateLogger<HomeController>();
|
@@ -53,5 +56,12 @@ public async Task<IActionResult> Postbody()
|
53 | 56 | var result = await _postbodyMemcachedClient.GetAsync<string>(PostbodyCacheKey);
|
54 | 57 | return result.Success ? Ok() : StatusCode(500);
|
55 | 58 | }
|
| 59 | + |
| 60 | + public IActionResult Uptime() |
| 61 | + { |
| 62 | + var server = options.Servers.First(); |
| 63 | + var uptime = _memcachedClient.Stats().GetUptime(new DnsEndPoint(server.Address, server.Port)); |
| 64 | + return Json(uptime); |
| 65 | + } |
56 | 66 | }
|
57 | 67 | }
|
0 commit comments