1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
|
;;;;; -*-coding: iso-8859-1;-*-
;;;;;
;;;;; Copyright (C) 1991-2002 Lysator Academic Computer Association.
;;;;;
;;;;; This file is part of the LysKOM Emacs LISP client.
;;;;;
;;;;; LysKOM is free software; you can redistribute it and/or modify it
;;;;; under the terms of the GNU General Public License as published by
;;;;; the Free Software Foundation; either version 2, or (at your option)
;;;;; any later version.
;;;;;
;;;;; LysKOM is distributed in the hope that it will be useful, but WITHOUT
;;;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;;;;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
;;;;; for more details.
;;;;;
;;;;; You should have received a copy of the GNU General Public License
;;;;; along with LysKOM; see the file COPYING. If not, write to
;;;;; Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
;;;;; or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
;;;;; MA 02139, USA.
;;;;;
;;;;; Please mail bug reports to bug-lyskom@lysator.liu.se.
;;;;;
;;;; ================================================================
;;;; ================================================================
;;;;
;;;; File: cache.el
;;;;
;;;; This file contains all functions which have to do with
;;;; caching various data types in the LysKOM client.
;;;;
;;;;
;;; ================================================================
;;; UConf-stat cache
(defun cache-get-uconf-stat (conf-no)
"Get uconf-stat for conference CONF-NO, or nil if nothing is cached.
If full conf-stat is cached, construct an uconf-stat from that data and
cache it."
(or (cache-assoc conf-no lyskom-uconf-cache)
(and (lyskom-have-feature long-conf-types)
(cache-construct-uconf-stat (cache-get-conf-stat conf-no)))))
(defun cache-construct-uconf-stat (conf)
"If conf is non-nil, create an uconf-stat from conf and cache it.
Return the new uconf-stat or nil"
(let ((tmp nil))
(and conf
(cache-add-uconf-stat
(setq tmp
(lyskom-create-uconf-stat (conf-stat->conf-no conf)
(conf-stat->name conf)
(conf-stat->conf-type conf)
(+
(conf-stat->first-local-no conf)
(conf-stat->no-of-texts conf))
(conf-stat->garb-nice conf)))))
tmp))
(defun cache-add-uconf-stat (uconf-stat)
"Insert a UCONF-STAT in the cache."
(cache-add (uconf-stat->conf-no uconf-stat)
uconf-stat
'lyskom-uconf-cache))
(defun cache-del-uconf-stat (conf-no)
"Delete a conf-stat from the cache. Args: CONF-NO."
(cache-del conf-no 'lyskom-uconf-cache)
(cache-del conf-no 'lyskom-conf-cache))
;;; ================================================================
;;; Conf-stat cache.
(defun cache-get-conf-stat (conf-no)
"Get conf-stat for conference CONF-NO, or nil if nothing is cached."
(cache-assoc conf-no lyskom-conf-cache))
(defun cache-add-conf-stat (conf-stat)
"Insert a CONF-STAT in the cache."
(cache-add (conf-stat->conf-no conf-stat) conf-stat 'lyskom-conf-cache))
(defun cache-del-conf-stat (conf-no)
"Delete a conf-stat from the cache. Args: CONF-NO."
(cache-del conf-no 'lyskom-conf-cache)
(cache-del conf-no 'lyskom-uconf-cache))
;;; ================================================================
;;; Pers-stat cache.
(defun cache-get-pers-stat (pers-no)
"Get pers-stat for person PERS-NO, or nil if nothing is cached."
(cache-assoc pers-no lyskom-pers-cache))
(defun cache-add-pers-stat (pers-stat)
"Insert a PERS-STAT in the cache."
(cache-add (pers-stat->pers-no pers-stat) pers-stat 'lyskom-pers-cache))
(defun cache-del-pers-stat (pers-no)
"Delete a pers-stat from the cache. Args: PERS-NO."
(cache-del pers-no 'lyskom-pers-cache))
;;; ================================================================
;;; Text-stat cache.
(defun cache-get-text-stat (text-no)
"Get text-stat for texton TEXT-NO, or nil if nothing is cached."
(cache-assoc text-no lyskom-text-cache))
(defun cache-add-text-stat (text-stat)
"Insert a TEXT-STAT in the cache."
(cache-add (text-stat->text-no text-stat) text-stat 'lyskom-text-cache))
(defun cache-del-text-stat (text-no)
"Delete a text-stat from the cache. Args: TEXT-NO."
(cache-del text-no 'lyskom-text-cache))
;;; ================================================================
;;; Text cache (the text strings).
(defun cache-get-text (text-no)
"Get text for textno TEXT-NO, or nil if nothing is cached."
(let ((tx (cache-assoc text-no lyskom-text-mass-cache)))
(cond
((lyskom-text-p tx) tx))))
(defun cache-add-text (text)
"Insert a TEXT in the cache."
(cache-add (text->text-no text) text 'lyskom-text-mass-cache))
(defun cache-del-text (text-no)
"Delete a text from the cache. Args: TEXT-NO."
(cache-del text-no 'lyskom-text-mass-cache))
;;; ================================================================
;;; Marked texts cache.
(defun cache-get-marked-texts ()
"Return the a list of marks for all marked texts."
lyskom-marked-text-cache)
(defun cache-set-marked-texts (mark-array)
"Sets the marks for all marked texts. A mark-list is an array, but we
want a list in the cache, so this remakes it into a list."
(setq lyskom-marked-text-cache (listify-vector mark-array)))
(defun cache-text-is-marked (text-no)
"Return the mark if the text text-no is marked by the current user,
otherwise return nil"
(let ((marks lyskom-marked-text-cache)
(mark nil))
(while (and (not (null marks))
(null mark))
(if (equal text-no (mark->text-no (car marks)))
(setq mark (car marks))
(setq marks (cdr marks))))
mark))
(defun cache-add-marked-text (text-no mark-type)
"Insert a mark into the cache. If it is already there, replace it."
(let ((marks lyskom-marked-text-cache)
(found nil)
(mark (lyskom-create-mark text-no mark-type)))
(while (and (not found)
(not (null marks)))
(if (and (car marks)
(equal text-no (mark->text-no (car marks))))
(progn
(setcar marks mark)
(setq found t))
(setq marks (cdr marks))))
(if (not found)
(setq lyskom-marked-text-cache
(cons mark lyskom-marked-text-cache)))))
(defun cache-del-marked-text (text-no)
"Remove the mark from the cache of marked texts if it is there.
+++BUG: A mark is replaced with a nil and not removed."
(let ((marks lyskom-marked-text-cache)
(found nil))
(while (and (not found)
(not (null marks)))
(if (equal text-no (mark->text-no (car marks)))
(progn
(setcar marks nil)
(setq found t))
(setq marks (cdr marks))))))
;;; ================================================================
;;; Static-session-info cache
(defun cache-get-static-session-info (session)
"Get static-session-info for session SESSION, or nil if nothing is cached."
(let ((tx (cache-assoc session lyskom-static-session-info-cache)))
(cond
((lyskom-static-session-info-p tx) tx))))
(defun cache-add-static-session-info (session info)
"Insert INFO in the cache."
(cache-add session info 'lyskom-static-session-info-cache))
;; NOTUSED: cache-del-static-session-info
(defun cache-del-static-session-info (session)
"Delete a text from the cache. Args: SESSION."
(cache-del session 'lyskom-static-session-info-cache))
;;; ================================================================
;;; Generic cache routines
(defvar lyskom-caches nil
"A list of all the caches in use.
This is used to clear all caches with `clear-all-caches'")
(defun cache-create (cache)
(set cache nil)
(setq lyskom-caches (cons cache lyskom-caches)))
(defun cache-assoc (key cache)
"Get data for item with key KEY from CACHE.
CACHE is an assoc-list in this implementation."
(cdr-safe (assoc key cache)))
(defun cache-add (key data cache)
"Add DATA to CACHE under the key KEY.
Args: KEY DATA CACHE.
CACHE is a (the only one) quoted variable pointing to the cache (an alist).
The variable might be changed."
(if (null (symbol-value cache))
(cache-create cache))
(let ((oldval (assoc key (symbol-value cache))))
(cond
((null oldval)
(set cache
(cons (cons key data)
(symbol-value cache))))
(t
(setcdr oldval data)))))
(defun cache-del (key cache)
"Delete item with key KEY from CACHE.
CACHE is the name of the variable that points to the cache."
(let ((oldval (assoc key (symbol-value cache))))
(if oldval
(setcdr oldval nil)))) ;A pair (key . nil) will remain.
;Fix this bug someday. +++
(defun cache-clear (cache)
(set cache nil)
(setq lyskom-caches (delete cache lyskom-caches)))
(defun clear-all-caches ()
(mapc (function (lambda (cache) (set cache nil)))
lyskom-caches)
(setq lyskom-caches nil))
;;; ================================================================
;;; lyskom-tell-server (this is also a sort of cache)
(def-kom-var lyskom-what-i-am-doing nil
"What the client thinks the server thinks the user is doing."
local)
(defun lyskom-tell-server (string)
"Tell the server what the user is doing. Args: STRING."
(unless lyskom-is-anonymous
(save-excursion
(when lyskom-buffer
(set-buffer lyskom-buffer))
(cond
((equal string lyskom-what-i-am-doing))
(t
(setq lyskom-what-i-am-doing string)
(initiate-change-what-i-am-doing 'background nil (or string "")))))))
(provide 'lyskom-cache)
|