tobbbe
8/26/2016 - 12:23 PM

c# API cache

namespace Test.MyApp
{
    public class MyAppCache
    {
        private static object _initLock = new object();
        private static ModelToCache _current = null;
        public static bool CacheIsInvalid = false;

        public static ModelToCache Current
        {
            get
            {
                lock (_initLock)
                {
                    if (_current == null || CacheIsInvalid)
                    {
                        CreateCache();
                    }
                    
                    return _current;
                }
            }
        }

        private MyAppCache()
        {

        }

        private static void CreateCache()
        {
            _current = new ModelToCache();
            // setup the instance
        }
    }
}