delphimvcframework/samples/outputcachewithredis/CommonsU.pas
Daniele Teti 54c82554e6 ADD Cache support based on Redis
MVCFramework.Controllers.CacheController.pas
2016-11-07 12:24:13 +01:00

36 lines
854 B
ObjectPascal

unit CommonsU;
interface
uses
System.SysUtils, System.Classes;
type
EWrongPage = class(Exception)
end;
procedure GetLimitByPage(const APage: Integer; out StartRec: Integer; out EndRec: Integer);
procedure MergePaginationMetaInfos(AURLFormat: String; AHeaders: TStrings; ACurrPage: Integer);
implementation
procedure MergePaginationMetaInfos(AURLFormat: String; AHeaders: TStrings; ACurrPage: Integer);
begin
AHeaders.Values['dmvc-next-page'] :=
Format(AURLFormat, [ACurrPage + 1]);
if ACurrPage > 1 then
AHeaders.Values['dmvc-prev-page'] :=
Format(AURLFormat, [ACurrPage - 1]);
end;
procedure GetLimitByPage(const APage: Integer; out StartRec: Integer; out EndRec: Integer);
begin
if APage < 1 then
raise EWrongPage.Create('Page must be greater than 0');
EndRec := APage * 10;
StartRec := EndRec - 9;
end;
end.