| 1 | using Core.Models.WebPage; |
| 2 | using Core.Servicers.Interfaces; |
| 3 | using System; |
| 4 | using System.Collections.Generic; |
| 5 | using System.Linq; |
| 6 | using System.Text; |
| 7 | using System.Threading.Tasks; |
| 8 | |
| 9 | namespace Core.Librarys |
| 10 | { |
| 11 | public static class SiteCache |
| 12 | { |
| 13 | private static List<Site> sites = new List<Site>(); |
| 14 | private static readonly int maxNum = 100; |
| 15 | public static Site Get(string key) |
| 16 | { |
| 17 | return sites.Where(m => m.Title.Equals(key)).FirstOrDefault(); |
| 18 | } |
| 19 | |
| 20 | public static List<Site> GetAll() |
| 21 | { |
| 22 | return sites; |
| 23 | } |
| 24 | |
| 25 | public static void Set(string key, string value) |
| 26 | { |
| 27 | if (Get(key) == null) |
| 28 | { |
| 29 | sites.Add(new Site() |
| 30 | { |
| 31 | Title = key, |
| 32 | Url = value |
| 33 | }); |
| 34 | |
| 35 | if (sites.Count > maxNum) |
| 36 | { |
| 37 | sites.RemoveAt(0); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | } |