/// <summary> /// Reads the specified id. /// </summary> /// <param name="id">The id.</param> /// <returns></returns> public static KioskLocationAttendance Read(int id) { string cacheKey = KioskLocationAttendance.CacheKey(id); ObjectCache cache = MemoryCache.Default; KioskLocationAttendance locationAttendance = cache[cacheKey] as KioskLocationAttendance; if (locationAttendance != null) { return(locationAttendance); } else { using (new Rock.Data.UnitOfWorkScope()) { var location = new LocationService().Get(id); if (location != null) { locationAttendance = new KioskLocationAttendance(); locationAttendance.LocationId = location.Id; locationAttendance.LocationName = location.Name; locationAttendance.Groups = new List <KioskGroupAttendance>(); var attendanceService = new AttendanceService(); foreach (var attendance in attendanceService.GetByDateAndLocation(DateTime.Today, location.Id)) { AddAttendanceRecord(locationAttendance, attendance); } var cachePolicy = new CacheItemPolicy(); cachePolicy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(60); cache.Set(cacheKey, locationAttendance, cachePolicy); return(locationAttendance); } } } return(null); }
/// <summary> /// Flushes the specified id. /// </summary> /// <param name="id">The id.</param> public static void Flush(int id) { ObjectCache cache = MemoryCache.Default; cache.Remove(KioskLocationAttendance.CacheKey(id)); }