source: trunk/gsdl/src/colservr/querycache.cpp@ 112

Last change on this file since 112 was 112, checked in by rjmcnab, 25 years ago

Standard header.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.8 KB
Line 
1/**********************************************************************
2 *
3 * querycache.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * PUT COPYRIGHT NOTICE HERE
7 *
8 * $Id: querycache.cpp 112 1999-01-12 01:51:06Z rjmcnab $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.2 1999/01/12 01:51:02 rjmcnab
15
16 Standard header.
17
18 Revision 1.1 1999/01/08 09:02:18 rjmcnab
19
20 Moved from src/library.
21
22 */
23
24
25#include "querycache.h"
26
27
28
29
30resultcacheel::resultcacheel ()
31{
32 accessnum = -1;
33}
34
35
36
37querycache::querycache (int themaxcachesize)
38{
39 if (themaxcachesize < 1) themaxcachesize = 1;
40
41 resultcache = new resultcacheel[themaxcachesize];
42
43 maxcachesize = themaxcachesize;
44 nextaccessnum = 1;
45}
46
47querycache::~querycache ()
48{
49 delete [] resultcache;
50}
51
52// returns true if the query was found in the cache
53// if the query was found then queryresults contains
54// the results
55bool querycache::find (const queryparamclass &queryparams,
56 queryresultsclass &queryresults)
57{
58 int i;
59
60 for (i=0; i < maxcachesize; i++)
61 {
62 if (resultcache[i].queryparameters == queryparams)
63 {
64 queryresults = resultcache[i].queryresults;
65 resultcache[i].accessnum = getnextaccessnum ();
66 return true;
67 }
68 }
69
70 return false;
71}
72
73
74void querycache::cache (const queryparamclass &queryparams,
75 const queryresultsclass &queryresults)
76{
77 int i = getfreecachenum();
78 resultcache[i].queryparameters = queryparams;
79 resultcache[i].queryresults = queryresults;
80 resultcache[i].accessnum = getnextaccessnum ();
81}
82
83int querycache::getnextaccessnum ()
84{
85 return nextaccessnum++;
86}
87
88int querycache::getfreecachenum ()
89{
90 int i;
91 int minaccessnum = 0;
92 int minaccessi = 0;
93
94 for (i=0; i < maxcachesize; i++)
95 {
96 if (resultcache[i].accessnum < minaccessnum)
97 minaccessi = i;
98 }
99
100 return i;
101}
102
Note: See TracBrowser for help on using the repository browser.