Cache
groups
Support for cache groups has been added to
the Win 32 Internet functions since Internet Explorer 5.0.
Working with cache groups in IECache is similar to working
with cache entries:
function
FindFirstGroup(var GroupID: Int64): DWORD;
function FindNextGroup(var GroupID: Int64):
BOOL;
function RetrieveGroups: DWORD;
property OnGroup;
A GroupID of type INT64 is returned for each group. You
use this GroupID in other group functions:
function DeleteGroup(GroupID: INT64): DWORD;
function GetGroupInfo(GroupID: INT64): DWORD;
function SetGroupInfo(GroupID: INT64): DWORD;
function AddUrlToGroup(GroupID: INT64; Url: string):
DWORD;
function RemoveUrlFromGroup(GroupID: INT64; Url: string):
DWORD;
Creating a
cache Group:
To Create a new Cache group use:
function CreateGroup:
INT64;
This function hands you the GroupID for
the created group. Before adding URLs to the Group it is
important to set Disk Quota for the group. Otherwise you
will receive a ERROR_NOT_ENOUGH_QUOTA. You should also set
a groupname, so you can find the group again after you
have forgot all about the GroupID-number. Use SetGroupInfo
to set information about the group. This function writes
the content of IECache.GroupInfo to the cache:
TGroupInfo = record
DiskUsage: DWORD; // in KB
DiskQuota: DWORD; //in KB
OwnerStorage: array[0..GROUP_OWNER_STORAGE_SIZE -
1] of DWORD; // in KB
GroupName: string;
end;
DiskUsage is read-only. You can use it to
get information about how much disk space the cache group
uses. OwnerStorage is optional. It can be used by a client
application to store information related to the group.
The following sample shows how to create a
new Cache group:
procedure
TForm1.Button1Click(Sender: TObject);
var
MyNewGroup : INT64;
begin
MyNewGroup:=IECache1.CreateGroup;
if MyNewGroup<>0 then begin
IECache1.GroupInfo.DiskQuota:=1000; {Kb}
IECache1.GroupInfo.GroupName:='My
New Cache Group';
Fillchar(IECache1.GroupInfo.OwnerStorage,4,#0);
IECache1.SetGroupInfo(MyNewGroup);
end;
end;
|
Adding URLs to
a cache Group:
function
AddUrlToGroup(GroupID: INT64; Url: string): DWORD;
The following code shows how to add
entries to a cache group. We want to add all *.gif-files
in the cache to 'My New Cache Group'. Since we don't have
the GroupID any longer, we first enumerate the existing
groups looking for Groupname='My New Cache Group'. We use FindFirstGroup
and FindNextGroup but could also have used RetrieveGroups
and OnGroup event. (There is no CloseFindGroups.)
In procedure Button3Click we enumerate the new entries
in the new cache group, passing the GroupID to
FindFirstEntry. All the *.gif entries are shown in the
listbox.
var
GroupID: INT64;
procedure TForm1.Button2Click(Sender:
TObject);
var
MainID: INT64;
ID: INT64;
begin
GroupID := 0;
with IECache1 do begin
if findfirstgroup(ID) =
S_OK then
while FindNextGroup(ID) do
if (GroupInfo.GroupName
= 'My New Cache Group') then GroupID:=ID;
end;
if GroupID <> 0 then
begin
if
IECache1.FindFirstEntry(0) = S_OK
then begin
if pos('.gif',
IECache1.EntryInfo.LocalFileName) > 0 then
IECache1.AddUrlToGroup(GroupID,
IECache1.EntryInfo.SourceUrlName);
while
IECache1.FindNextEntry = S_OK do
if pos('.gif',
IECache1.EntryInfo.LocalFileName) > 0 then
IECache1.AddUrlToGroup(GroupID,
IECache1.EntryInfo.SourceUrlName);
end;
IECache1.CloseFindEntry;
end;
end;
procedure TForm1.Button3Click(Sender:
TObject);
begin
if GroupID<>0 then begin
if
IECache1.FindFirstEntry(GroupID) = S_OK
then begin
Listbox1.Items.Add(IECache1.EntryInfo.SourceUrlName);
while
IECache1.FindNextEntry = S_OK do
Listbox1.Items.Add(IECache1.EntryInfo.SourceUrlName);
end;
IECache1.CloseFindEntry;
end;
end;
|
Deleting
cache Group:
function
DeleteGroup(GroupID: INT64): DWORD;
function RemoveUrlFromGroup(GroupID: INT64; Url: string):
DWORD;
Use RemoveUrlFromGroup to
delete a single entry in the group. If you remove all
entries in the group, the group still exists. DeleteGroup
deletes the group and all entries in the group.