Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Common / QueryCache / QueryCacheKey.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="QueryCacheKey.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner  Microsoft
7 // @backupOwner Microsoft
8 //------------------------------------------------------------------------------
9
10 namespace System.Data.Common.QueryCache
11 {
12     using System;
13     using System.Collections.Generic;
14     using System.Text;
15
16
17     /// <summary>
18     /// represents an abstract cache key
19     /// </summary>
20     internal abstract class QueryCacheKey
21     {
22         #region Constants
23         protected const int EstimatedParameterStringSize = 20;
24         #endregion
25
26         #region Fields
27         /// <summary>
28         /// entry hit counter
29         /// </summary>
30         private uint _hitCount;
31
32         /// <summary>
33         /// aging index
34         /// </summary>
35         private int _agingIndex;
36
37         /// <summary>
38         /// default string comparison kind - Ordinal
39         /// </summary>
40         protected static StringComparison _stringComparison = StringComparison.Ordinal;
41         #endregion
42
43         #region Constructor
44         protected QueryCacheKey()
45         {
46             _hitCount = 1;
47         }
48         #endregion
49
50         #region Abstract Methods
51         /// <summary>
52         /// Determines whether two instances of QueryCacheContext are equal. 
53         /// Equality is value based.
54         /// </summary>
55         /// <param name="obj"></param>
56         /// <returns></returns>
57         public abstract override bool Equals( object obj );
58
59         /// <summary>
60         /// Returns QueryCacheContext instance HashCode
61         /// </summary>
62         /// <returns></returns>
63         public abstract override int GetHashCode();
64         #endregion
65
66         #region Internal API
67         /// <summary>
68         /// Cache entry hit count
69         /// </summary>
70         internal uint HitCount
71         {
72             get 
73             { 
74                 return _hitCount; 
75             }
76             
77             set 
78             { 
79                 _hitCount = value; 
80             }
81         }
82
83         /// <summary>
84         /// Gets/Sets Aging index for cache entry
85         /// </summary>
86         internal int AgingIndex
87         {
88             get 
89             { 
90                 return _agingIndex; 
91             }
92             
93             set 
94             { 
95                 _agingIndex = value; 
96             }
97         }
98
99         /// <summary>
100         /// Updates hit count
101         /// </summary>
102         internal void UpdateHit()
103         {
104             if (uint.MaxValue != _hitCount)
105             {
106                 unchecked { _hitCount++; }
107             }
108         }
109
110         /// <summary>
111         /// default string comparer
112         /// </summary>
113         /// <param name="s"></param>
114         /// <param name="t"></param>
115         /// <returns></returns>
116         protected virtual bool Equals( string s, string t )
117         {
118             return String.Equals(s, t, _stringComparison);
119         }
120         #endregion
121     }
122 }