From: Lars Rune Nøstdal
Subject: Re: virtual, static, member (?)
Date:
Message-ID: <1227231524.16144.42.camel@blackbox.nostdal.org>
> >
> > hm .. yay, it seems to work! .. i gotta try this out now; so i'll stop
> > spamming :}
> >
>
trying it in a real scenario (db stuff, postmodern library):
(defclass user ()
((id :reader id-of
:col-type integer
:initform (with-db-connection (sequence-next 'virtual-users-id-seq)))
(domain-id :accessor domain-id-of :initarg :domain
:col-type integer)
(mailuser :accessor mailuser-of :initarg :mailuser
:col-type string)
(password :accessor password-of :initarg :password
:col-type string)
(user-class-id :accessor user-class-id-of :initarg :user-class
:col-type integer)
(vacation-p :accessor vacation-p-of :initarg :vacation-p
:col-type boolean
:initform nil)
(vacation-subject :accessor vacation-subject-of :initarg :vacation-subject
:col-type string
:initform "")
(vacation-body :accessor vacation-body-of :initarg :vacation-body
:col-type string
:initform ""))
(:metaclass dao-class)
(:table-name virtual-users)
(:keys id))
(defun get-user (id)
"Returns an instance of USER or NIL."
(declare (integer id))
(with-db-connection
(get-dao 'user id)))
HIN-SMA> (time (dotimes (i 50000) (get-user 1)))
Evaluation took:
21.370 seconds of real time
9.496594 seconds of total run time (7.720483 user, 1.776111 system)
[ Run times consist of 0.508 seconds GC time, and 8.989 seconds non-GC time. ]
44.44% CPU
120 forms interpreted
171 lambdas converted
47,256,846,606 processor cycles
676,626,832 bytes consed
after:
(defclass user (cached-object)
.....etc...)
(defun get-user (id)
"Returns an instance of USER or NIL."
(declare (integer id))
(multiple-value-bind (user found-p)
(get-obj id 'user)
(if found-p
user
(with-db-connection
(get-dao 'user id)))))
HIN-SMA> (time (dotimes (i 50000) (get-user 1)))
Evaluation took:
0.294 seconds of real time
0.268016 seconds of total run time (0.248015 user, 0.020001 system)
[ Run times consist of 0.168 seconds GC time, and 0.101 seconds non-GC time. ]
91.16% CPU
40 lambdas converted
651,683,362 processor cycles
1,280,064 bytes consed
..works for me :)