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

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

Moved from src/library.

  • 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 110 1999-01-08 09:02:22Z rjmcnab $
9 *
10 *********************************************************************/
11
12/*
13 $Log$
14 Revision 1.1 1999/01/08 09:02:18 rjmcnab
15
16 Moved from src/library.
17
18 */
19
20static char *RCSID = "$Id: querycache.cpp 110 1999-01-08 09:02:22Z rjmcnab $";
21
22
23#include "querycache.h"
24
25
26
27
28resultcacheel::resultcacheel ()
29{
30 accessnum = -1;
31}
32
33
34
35querycache::querycache (int themaxcachesize)
36{
37 if (themaxcachesize < 1) themaxcachesize = 1;
38
39 resultcache = new resultcacheel[themaxcachesize];
40
41 maxcachesize = themaxcachesize;
42 nextaccessnum = 1;
43}
44
45querycache::~querycache ()
46{
47 delete [] resultcache;
48}
49
50// returns true if the query was found in the cache
51// if the query was found then queryresults contains
52// the results
53bool querycache::find (const queryparamclass &queryparams,
54 queryresultsclass &queryresults)
55{
56 int i;
57
58 for (i=0; i < maxcachesize; i++)
59 {
60 if (resultcache[i].queryparameters == queryparams)
61 {
62 queryresults = resultcache[i].queryresults;
63 resultcache[i].accessnum = getnextaccessnum ();
64 return true;
65 }
66 }
67
68 return false;
69}
70
71
72void querycache::cache (const queryparamclass &queryparams,
73 const queryresultsclass &queryresults)
74{
75 int i = getfreecachenum();
76 resultcache[i].queryparameters = queryparams;
77 resultcache[i].queryresults = queryresults;
78 resultcache[i].accessnum = getnextaccessnum ();
79}
80
81int querycache::getnextaccessnum ()
82{
83 return nextaccessnum++;
84}
85
86int querycache::getfreecachenum ()
87{
88 int i;
89 int minaccessnum = 0;
90 int minaccessi = 0;
91
92 for (i=0; i < maxcachesize; i++)
93 {
94 if (resultcache[i].accessnum < minaccessnum)
95 minaccessi = i;
96 }
97
98 return i;
99}
100
Note: See TracBrowser for help on using the repository browser.