Skip to content

Commit fa9ec4a

Browse files
committed
new MemoryCache
1 parent 675bdfe commit fa9ec4a

5 files changed

+1086
-0
lines changed

Quick.MemoryCache.Compressor.GZip.pas

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{ ***************************************************************************
2+
3+
Copyright (c) 2016-2019 Kike Pérez
4+
5+
Unit : Quick.MemoryCache.Compressor.GZip
6+
Description : Compress Cache data
7+
Author : Kike Pérez
8+
Version : 1.0
9+
Created : 14/07/2019
10+
Modified : 15/09/2019
11+
12+
This file is part of QuickLib: https://github.com/exilon/QuickLib
13+
14+
***************************************************************************
15+
16+
Licensed under the Apache License, Version 2.0 (the "License");
17+
you may not use this file except in compliance with the License.
18+
You may obtain a copy of the License at
19+
20+
http://www.apache.org/licenses/LICENSE-2.0
21+
22+
Unless required by applicable law or agreed to in writing, software
23+
distributed under the License is distributed on an "AS IS" BASIS,
24+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
See the License for the specific language governing permissions and
26+
limitations under the License.
27+
28+
*************************************************************************** }
29+
30+
unit Quick.MemoryCache.Compressor.GZip;
31+
32+
{$i QuickLib.inc}
33+
34+
interface
35+
36+
uses
37+
Quick.Compression,
38+
Quick.MemoryCache.Types;
39+
40+
type
41+
42+
TCacheCompressorGZip = class(TInterfacedObject,ICacheCompressor)
43+
public
44+
function Compress(const aValue : string) : string;
45+
function Decompress(const aValue : string) : string;
46+
end;
47+
48+
implementation
49+
50+
{ TCacheCompresorGZip }
51+
52+
function TCacheCompressorGZip.Compress(const aValue: string): string;
53+
begin
54+
Result := CompressGZipString(aValue,TCompressionLevel.zcFastest);
55+
end;
56+
57+
function TCacheCompressorGZip.Decompress(const aValue: string): string;
58+
begin
59+
Result := DeCompressGZipString(aValue);
60+
end;
61+
62+
end.

Quick.MemoryCache.Compressor.LZO.pas

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{ ***************************************************************************
2+
3+
Copyright (c) 2016-2019 Kike Pérez
4+
5+
Unit : Quick.MemoryCache.Compressor.LZO
6+
Description : Compress Cache data
7+
Author : Kike Pérez
8+
Version : 1.0
9+
Created : 15/07/2019
10+
Modified : 22/09/2019
11+
12+
This file is part of QuickLib: https://github.com/exilon/QuickLib
13+
14+
***************************************************************************
15+
16+
Licensed under the Apache License, Version 2.0 (the "License");
17+
you may not use this file except in compliance with the License.
18+
You may obtain a copy of the License at
19+
20+
http://www.apache.org/licenses/LICENSE-2.0
21+
22+
Unless required by applicable law or agreed to in writing, software
23+
distributed under the License is distributed on an "AS IS" BASIS,
24+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
See the License for the specific language governing permissions and
26+
limitations under the License.
27+
28+
*************************************************************************** }
29+
30+
unit Quick.MemoryCache.Compressor.LZO;
31+
32+
{$i QuickLib.inc}
33+
34+
interface
35+
36+
uses
37+
Quick.MemoryCache.Types,
38+
Quick.Compression.LZO;
39+
40+
type
41+
42+
TCacheCompressorLZO = class(TInterfacedObject,ICacheCompressor)
43+
public
44+
function Compress(const aValue : string) : string;
45+
function Decompress(const aValue : string) : string;
46+
end;
47+
48+
implementation
49+
50+
{ TCacheCompresorLZO }
51+
52+
function TCacheCompressorLZO.Compress(const aValue: string): string;
53+
var
54+
lzo : TLZOCompressor;
55+
begin
56+
lzo := TLZOCompressor.Create;
57+
try
58+
Result := lzo.Compress(aValue);
59+
finally
60+
lzo.Free;
61+
end;
62+
end;
63+
64+
function TCacheCompressorLZO.Decompress(const aValue: string): string;
65+
var
66+
lzo : TLZOCompressor;
67+
begin
68+
lzo := TLZOCompressor.Create;
69+
try
70+
Result := lzo.Decompress(aValue);
71+
finally
72+
lzo.Free;
73+
end;
74+
end;
75+
76+
end.

Quick.MemoryCache.Serializer.Json.pas

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{ ***************************************************************************
2+
3+
Copyright (c) 2016-2019 Kike Pérez
4+
5+
Unit : Quick.MemoryCache.Serializer.Json
6+
Description : Cache Json serializer
7+
Author : Kike Pérez
8+
Version : 1.0
9+
Created : 14/07/2019
10+
Modified : 02/11/2019
11+
12+
This file is part of QuickLib: https://github.com/exilon/QuickLib
13+
14+
***************************************************************************
15+
16+
Licensed under the Apache License, Version 2.0 (the "License");
17+
you may not use this file except in compliance with the License.
18+
You may obtain a copy of the License at
19+
20+
http://www.apache.org/licenses/LICENSE-2.0
21+
22+
Unless required by applicable law or agreed to in writing, software
23+
distributed under the License is distributed on an "AS IS" BASIS,
24+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
See the License for the specific language governing permissions and
26+
limitations under the License.
27+
28+
*************************************************************************** }
29+
30+
unit Quick.MemoryCache.Serializer.Json;
31+
32+
{$i QuickLib.inc}
33+
34+
interface
35+
36+
uses
37+
RTTI,
38+
//System.JSON.Serializers,
39+
Quick.Json.Serializer,
40+
Quick.MemoryCache.Types;
41+
42+
type
43+
44+
TCacheJsonSerializer = class(TInterfacedObject,ICacheSerializer)
45+
private
46+
fJsonSerializer : TJsonSerializer;
47+
public
48+
constructor Create;
49+
destructor Destroy; override;
50+
function Serialize(aObject : TObject) : string; overload;
51+
function Serialize(aArray : TArray<string>) : string; overload;
52+
function Serialize(aArray: TArray<TObject>): string; overload;
53+
procedure Deserialize(const aValue : string; aObject : TObject); overload;
54+
procedure Deserialize(const aValue : string; var aArray : TArray<string>); overload;
55+
procedure Deserialize(const aValue : string; var aArray: TArray<TObject>); overload;
56+
end;
57+
58+
59+
implementation
60+
61+
{ TCacheJsonSerializer }
62+
63+
constructor TCacheJsonSerializer.Create;
64+
begin
65+
fJsonSerializer := TJsonSerializer.Create(TSerializeLevel.slPublicProperty,False);
66+
//fJsonSerializer := TJsonSerializer.Create;
67+
end;
68+
69+
destructor TCacheJsonSerializer.Destroy;
70+
begin
71+
fJsonSerializer.Free;
72+
inherited;
73+
end;
74+
75+
function TCacheJsonSerializer.Serialize(aObject: TObject): string;
76+
begin
77+
Result := fJsonSerializer.ObjectToJson(aObject,False);
78+
//Result := fJsonSerializer.Serialize<TObject>(aObject);
79+
end;
80+
81+
function TCacheJsonSerializer.Serialize(aArray: TArray<string>): string;
82+
begin
83+
Result := fJsonSerializer.ArrayToJson<string>(aArray);
84+
end;
85+
86+
function TCacheJsonSerializer.Serialize(aArray: TArray<TObject>): string;
87+
begin
88+
Result := fJsonSerializer.ArrayToJson<TObject>(aArray);
89+
end;
90+
91+
procedure TCacheJsonSerializer.Deserialize(const aValue: string; aObject: TObject);
92+
begin
93+
fJsonSerializer.JsonToObject(aObject,aValue);
94+
//aObject := fJsonSerializer.Deserialize<TObject>(aValue);
95+
end;
96+
97+
procedure TCacheJsonSerializer.Deserialize(const aValue: string; var aArray: TArray<string>);
98+
begin
99+
aArray := fJsonSerializer.JsonToArray<string>(aValue);
100+
end;
101+
102+
procedure TCacheJsonSerializer.Deserialize(const aValue: string; var aArray: TArray<TObject>);
103+
begin
104+
aArray := fJsonSerializer.JsonToArray<TObject>(aValue);
105+
end;
106+
107+
end.

Quick.MemoryCache.Types.pas

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{ ***************************************************************************
2+
3+
Copyright (c) 2016-2019 Kike Pérez
4+
5+
Unit : Quick.MemoryCache.Types
6+
Description : Memory Cache Types
7+
Author : Kike Pérez
8+
Version : 1.0
9+
Created : 14/07/2019
10+
Modified : 15/09/2019
11+
12+
This file is part of QuickLib: https://github.com/exilon/QuickLib
13+
14+
***************************************************************************
15+
16+
Licensed under the Apache License, Version 2.0 (the "License");
17+
you may not use this file except in compliance with the License.
18+
You may obtain a copy of the License at
19+
20+
http://www.apache.org/licenses/LICENSE-2.0
21+
22+
Unless required by applicable law or agreed to in writing, software
23+
distributed under the License is distributed on an "AS IS" BASIS,
24+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
See the License for the specific language governing permissions and
26+
limitations under the License.
27+
28+
*************************************************************************** }
29+
30+
unit Quick.MemoryCache.Types;
31+
32+
{$i QuickLib.inc}
33+
34+
interface
35+
36+
uses
37+
RTTI;
38+
39+
type
40+
41+
ICacheEntry = interface
42+
['{3158454E-07D5-41A2-A0FA-D3917F6B58C1}']
43+
function GetCreationDate: TDateTime;
44+
function GetData: string;
45+
function GetExpiration: Cardinal;
46+
function GetExpirationDate: TDateTime;
47+
procedure SetCreationDate(const Value: TDateTime);
48+
procedure SetData(const Value: string);
49+
procedure SetExpirationDate(const Value: TDateTime);
50+
procedure SetExpiration(aMilliseconds : Cardinal);
51+
property CreationDate : TDateTime read GetCreationDate write SetCreationDate;
52+
property Expiration : Cardinal read GetExpiration write SetExpiration;
53+
property ExpirationDate : TDateTime read GetExpirationDate write SetExpirationDate;
54+
property Data : string read GetData write SetData;
55+
function Size : Integer;
56+
function IsExpired : Boolean;
57+
end;
58+
59+
ICacheCompressor = interface
60+
['{DE4FB31F-0A0B-49AF-88A6-41689C316DFE}']
61+
function Compress(const aValue : string) : string;
62+
function Decompress(const aValue : string) : string;
63+
end;
64+
65+
ICacheSerializer = interface
66+
['{F26B99AE-5080-4EDB-80CF-508E1A6F9EDE}']
67+
function Serialize(aObject : TObject) : string; overload;
68+
function Serialize(aArray : TArray<string>) : string; overload;
69+
function Serialize(aArray: TArray<TObject>): string; overload;
70+
procedure Deserialize(const aValue : string; aObject : TObject); overload;
71+
procedure Deserialize(const aValue : string; var aArray : TArray<string>); overload;
72+
procedure Deserialize(const aValue : string; var aArray: TArray<TObject>); overload;
73+
end;
74+
75+
implementation
76+
77+
end.

0 commit comments

Comments
 (0)