Last change
on this file since 4 was 4, checked in by sjboddie, 25 years ago |
Initial revision
|
-
Property svn:executable
set to
*
-
Property svn:keywords
set to
Author Date Id Revision
|
File size:
1.4 KB
|
Line | |
---|
1 | #include "querycache.h"
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 | resultcacheel::resultcacheel ()
|
---|
6 | {
|
---|
7 | accessnum = -1;
|
---|
8 | }
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 | querycache::querycache (int themaxcachesize)
|
---|
13 | {
|
---|
14 | if (themaxcachesize < 1) themaxcachesize = 1;
|
---|
15 |
|
---|
16 | resultcache = new resultcacheel[themaxcachesize];
|
---|
17 |
|
---|
18 | maxcachesize = themaxcachesize;
|
---|
19 | nextaccessnum = 1;
|
---|
20 | }
|
---|
21 |
|
---|
22 | querycache::~querycache ()
|
---|
23 | {
|
---|
24 | delete [] resultcache;
|
---|
25 | }
|
---|
26 |
|
---|
27 | // returns true if the query was found in the cache
|
---|
28 | // if the query was found then queryresults contains
|
---|
29 | // the results
|
---|
30 | bool querycache::find (const queryparamclass &queryparams,
|
---|
31 | queryresultsclass &queryresults)
|
---|
32 | {
|
---|
33 | int i;
|
---|
34 |
|
---|
35 | for (i=0; i < maxcachesize; i++)
|
---|
36 | {
|
---|
37 | if (resultcache[i].queryparameters == queryparams)
|
---|
38 | {
|
---|
39 | queryresults = resultcache[i].queryresults;
|
---|
40 | resultcache[i].accessnum = getnextaccessnum ();
|
---|
41 | return true;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | return false;
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | void querycache::cache (const queryparamclass &queryparams,
|
---|
50 | const queryresultsclass &queryresults)
|
---|
51 | {
|
---|
52 | int i = getfreecachenum();
|
---|
53 | resultcache[i].queryparameters = queryparams;
|
---|
54 | resultcache[i].queryresults = queryresults;
|
---|
55 | resultcache[i].accessnum = getnextaccessnum ();
|
---|
56 | }
|
---|
57 |
|
---|
58 | int querycache::getnextaccessnum ()
|
---|
59 | {
|
---|
60 | return nextaccessnum++;
|
---|
61 | }
|
---|
62 |
|
---|
63 | int querycache::getfreecachenum ()
|
---|
64 | {
|
---|
65 | int i;
|
---|
66 | int minaccessnum = 0;
|
---|
67 | int minaccessi = 0;
|
---|
68 |
|
---|
69 | for (i=0; i < maxcachesize; i++)
|
---|
70 | {
|
---|
71 | if (resultcache[i].accessnum < minaccessnum)
|
---|
72 | minaccessi = i;
|
---|
73 | }
|
---|
74 |
|
---|
75 | return i;
|
---|
76 | }
|
---|
77 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.