namespace ConsoleApplication1
{
    using System.Threading;

    using DynaCache;

    using Ninject;

    class Program
    {
        static void Main(string[] args)
        {
            var container = new StandardKernel();
            container.Bind<IDynaCacheService>().To<MemoryCacheService>().InSingletonScope();
            container.Bind<ITestClass>().To(Cacheable.CreateType<TestClass>());

            for (var i = 0; i < 10; i++)
            {
                var instance = container.Get<ITestClass>();

                // Every 2 seconds the output will change
                Console.WriteLine(instance.GetData(53));
                Thread.Sleep(500);
            }
        }
    }

    public class TestClass : ITestClass
    {
        [CacheableMethod(2)]
        public virtual string GetData(int id)
        {
            return String.Format("{0} - produced at {1:HH:mm:ss.ffff tt}", id, DateTime.Now);
        }
    }

    public interface ITestClass
    {
        string GetData(int id);
    }
}

Last edited Jun 27, 2014 at 10:11 PM by MikeGoatly, version 1

Comments

No comments yet.