In .:
[mono.git] / mcs / class / System.Data / System.Data.Common / DbMetaDataCache.cs
1 /*\r
2   * Copyright (c) 2002-2004 Mainsoft Corporation.\r
3   *\r
4   * Permission is hereby granted, free of charge, to any person obtaining a\r
5   * copy of this software and associated documentation files (the "Software"),\r
6   * to deal in the Software without restriction, including without limitation\r
7   * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
8   * and/or sell copies of the Software, and to permit persons to whom the\r
9   * Software is furnished to do so, subject to the following conditions:\r
10   *\r
11   * The above copyright notice and this permission notice shall be included in\r
12   * all copies or substantial portions of the Software.\r
13   *\r
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r
19   * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
20   * DEALINGS IN THE SOFTWARE.\r
21   */\r
22 \r
23 using System;\r
24 using System.Collections;\r
25 \r
26 using java.sql;\r
27 \r
28 namespace System.Data.Common\r
29 {\r
30         #region AbstractDbMetaDataCache\r
31 \r
32         internal abstract class AbstractDbMetaDataCache\r
33         {\r
34                 Hashtable _cache;\r
35                 const int MINUTES_TIMEOUT = 10;\r
36                 private long _timestamp;\r
37 \r
38                 protected AbstractDbMetaDataCache()\r
39                 {\r
40                         _cache = Hashtable.Synchronized(new Hashtable());\r
41                 }\r
42 \r
43                 protected Hashtable Cache \r
44                 {\r
45                         get\r
46                         {\r
47                                 long now = DateTime.Now.Ticks;\r
48                                 if (now - _timestamp > MINUTES_TIMEOUT * TimeSpan.TicksPerMinute)\r
49                                 {\r
50                                         _timestamp = now;\r
51                                         _cache.Clear();\r
52                                 }\r
53 \r
54                                 return _cache;\r
55                         }\r
56                 }\r
57         }\r
58 \r
59         #endregion\r
60 }\r