You are not logged in.
Pages: 1
hi,
When I want to make some test, duto cache, the time is varied. Try to set Server UseCache to False failed. It seems not ready for disable cache.
Is there a plan to make this feature ready?
Offline
There are several levels of cache.
See the SAD 1.18 pdf about that.
Or the older (probably out of date) http://blog.synopse.info/post/2012/02/14/ORM-cache
Offline
What I mean is Cache in server side, the class of TSQLDataBase, which has a public property UseCache
TSQLDataBase = class
......
/// if this property is set, all ExecuteJSON() responses will be cached
// - cache is flushed on any write access to the DB (any not SELECT statement)
// - cache is consistent only if ExecuteJSON() Expand parameter is constant
// - cache is used by TSQLDataBase.ExecuteJSON() and TSQLTableDB.Create()
property UseCache: boolean read GetUseCache write SetUseCache;
The class seems not check the fCache=nil, so, cannot set this property to false.
Offline
fCache=nil is checked in [get]UseCache:
function TSQLDataBase.GetUseCache: boolean;
begin
result := (Self<>nil) and (fCache<>nil);
end;
procedure TSQLDataBase.SetUseCache(const Value: boolean);
begin
if self<>nil then
if Value<>UseCache then
if Value then
fCache := TSynCache.Create(16384*1024,true) else
FreeAndNil(fCache);
end;
Code sounds correct here.
Offline
Please ref
function TSQLDataBase.LockJSON(const aSQL: RawUTF8; aResultCount: PPtrInt): RawUTF8;
begin
if self=nil then
exit; // avoid GPF in case of call from a static-only server
EnterCriticalSection(fLock); // cache access is also protected by fLock
try
if isSelect(pointer(aSQL)) then begin
result := fCache.Find(aSQL,aResultCount); // try to get JSON result from cache
if result<>'' then begin
fCache not checked for nil
Offline
Please read the code!
function TSynCache.Find(const aKey: RawUTF8; aResultTag: PPtrInt): RawUTF8;
var added: boolean;
begin
if (self=nil) or (aKey='') then begin
fFindLastAddedIndex := -1;
result := '';
end else begin
(...)
So fCache is checked for nil !
Offline
Sorry, I don't know we can call the method of class which is nil. Usally, it's not safe. Thank you for knowing this.
But here, do have the problem, you assigned value to fFindLastAddedIndex which get av.
the line
fFindLastAddedIndex := -1;
shall be removed.
Offline
Sorry, I don't know we can call the method of class which is nil. Usally, it's not safe. Thank you for knowing this.
It is always safe, unless the method is virtual.
If you come from a Java background, where every method is virtual, you can easily be confused.
But in Delphi, it is pretty valid and convenient to call a non virtual method with self=nil.
But here, do have the problem, you assigned value to fFindLastAddedIndex which get av.
the linefFindLastAddedIndex := -1;
shall be removed.
AFAIK fFindLastAddedIndex use is just correct, and will never get an access violation.
I've added some comments to help you understand the algorithm.
See http://synopse.info/fossil/info/19ac0042ff
Do not make assumption: use the debugger to find out what is happenning if it is not clear what the code does.
And provide some code to reproduce any problem, if there is any.
Offline
I certainly not make assumption, I use XE to trace here. fFindLastAddedIndex is not accessible. assigned value to fFindLastAddedIndex do get AV.
this problem just occurred by set Usecache=False. maybe late I can give a code to test it.
anyway, here wish you happy new year!
Happy new year to erverybody here!
Offline
test code, use mormot sample, 02 - Embedded SQLite3 ORM
program Project02;
uses
Forms,
SysUtils,
mORMot,
mORMotSQLite3, SynSQLite3Static,
Unit1 in '..\01 - In Memory ORM\Unit1.pas' {Form1},
SampleData in '..\01 - In Memory ORM\SampleData.pas';
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Form1.Caption := ' Sample 02 - Embedded SQLite3 ORM';
Form1.Database := TSQLRestServerDB.Create(Form1.Model,
ChangeFileExt(paramstr(0),'.db3'));
TSQLRestServerDB(Form1.Database).CreateMissingTables(0);
TSQLRestServerDB(Form1.Database).DB.UseCache:=false; //add this line to disable cache
Application.Run;
end.
write ok, but read av occurred
Offline
Yes!
With a simple test program, it was easy to find what you meant, and finally fix the issue!
See http://synopse.info/fossil/info/7f89ac7467
Thanks for the feedback!
Offline
Pages: 1