Rock.CheckIn.KioskLocationAttendance.CacheKey C# (CSharp) Method

CacheKey() private static method

Caches the key.
private static CacheKey ( int id ) : string
id int The id.
return string
        private static string CacheKey( int id )
        {
            return string.Format( "Rock:CheckIn:KioskLocationAttendance:{0}", id );
        }

Usage Example

        /// <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);
        }
All Usage Examples Of Rock.CheckIn.KioskLocationAttendance::CacheKey