CacheItemComparer.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // CacheItemComparer.cs
  3. //
  4. // Author:
  5. // Marek Habersack <[email protected]>
  6. //
  7. // Copyright (c) 2010, Marek Habersack
  8. //
  9. // All rights reserved.
  10. //
  11. // Redistribution and use in source and binary forms, with or without modification, are permitted
  12. // provided that the following conditions are met:
  13. //
  14. // * Redistributions of source code must retain the above copyright notice, this list of
  15. // conditions and the following disclaimer.
  16. // * Redistributions in binary form must reproduce the above copyright notice, this list of
  17. // conditions and the following disclaimer in the documentation and/or other materials
  18. // provided with the distribution.
  19. // * Neither the name of Marek Habersack nor the names of its contributors may be used to
  20. // endorse or promote products derived from this software without specific prior written
  21. // permission.
  22. //
  23. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27. // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28. // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30. // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. //
  35. using System;
  36. using System.Collections;
  37. using System.Web.Caching;
  38. namespace Tester
  39. {
  40. class CacheItemComparer : IComparer
  41. {
  42. public int Compare (object o1, object o2)
  43. {
  44. CacheItem x = o1 as CacheItem;
  45. CacheItem y = o2 as CacheItem;
  46. if (x == null && y == null)
  47. return 0;
  48. if (x == null)
  49. return 1;
  50. if (y == null)
  51. return -1;
  52. if (x.ExpiresAt == y.ExpiresAt)
  53. return 0;
  54. return x.ExpiresAt < y.ExpiresAt ? -1 : 1;
  55. }
  56. }
  57. }