CacheKey() 개인적인 정적인 메소드

Caches the key.
private static CacheKey ( int id ) : string
id int The id.
리턴 string
예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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));
        }