---++!! !ManagedResourceStore %TOC{title="Contents:"}% %STARTINCLUDE% ---++ ManagedResourceStore : public <localserver> | *Title* | ManagedResourceStore : public <localserver> | | *Author(s)* | LiXizhi | | *Date* | 2008/2/25 | | *File* | script/kids/3DMapSystemApp/localserver/ManagedResourceStore.lua | ---+++ Description A ManagedResourceStore represents a set of entries in the WebCacheDB and allows the set to be managed as a group. The identifying properties of a LocalServer are its domain, name, required_cookie, and server_type. %T% __Sample Code__ <verbatim> NPL.load("(gl)script/kids/3DMapSystemApp/localserver/ManagedResourceStore .lua"); </verbatim> ---+++ Member Functions ---++++ !ManagedResourceStore:new <verbatim>------------------------------------------ ManagedResourceStore : public <localserver> ------------------------------------------ local ManagedResourceStore = commonlib.inherit(Map3DSystem.localserver.localserver, { -- type of WebCacheDB.ServerType server_type_ = WebCacheDB.ServerType.MANAGED_RESOURCE_STORE, -- default policy Cache_policy = Map3DSystem.localserver.CachePolicy:new("access plus 1 month"), }</verbatim>); commonlib.setfield("Map3DSystem.localserver.ManagedResourceStore", ManagedResourceStore); __syntax__ <verbatim>function ManagedResourceStore:new(o)</verbatim> __parameters__ | *o* | | ---++++ !ManagedResourceStore:CreateOrOpen ---------------------------------- public member functions: ---------------------------------- Initializes an instance and inserts rows in the Servers and Versions table of the DB if needed __syntax__ <verbatim>function ManagedResourceStore:CreateOrOpen(security_origin, name, required_cookie) </verbatim> __parameters__ | *security* | | | *origin* | | | *name* | | | *required* | | | *cookie* | | ---++++ !ManagedResourceStore:Open Initializes an instance from its server_id. Will not insert rows into the Servers or Versions table of the DB. If the expected rows are not present in the Servers and Versions table, this method fails and returns false. __syntax__ <verbatim>function ManagedResourceStore:Open(server_id)</verbatim> __parameters__ | *server* | | | *id* | | ---++++ !ManagedResourceStore:GetManifestUrl Get the manifest url for this store * _param_ __manifest__ :_url: string * _return_ ____ : the manifest url (maybe ""), it returns nil if failed. __syntax__ <verbatim>function ManagedResourceStore:GetManifestUrl(manifest_url)</verbatim> __parameters__ | *manifest* | _url: string | | *url* | | ---++++ !ManagedResourceStore:SetManifestUrl Sets the manifest url for this store * _param_ __manifest__ :_url: string __syntax__ <verbatim>function ManagedResourceStore:SetManifestUrl(manifest_url)</verbatim> __parameters__ | *manifest* | _url: string | | *url* | | ---++++ !ManagedResourceStore:HasVersion returns if the application has a version in the desired state or a version string. * _param_ __state__ : it int, it is WebCacheDB.VersionReadyState, if string, it is the version string. __syntax__ <verbatim>function ManagedResourceStore:HasVersion(state) </verbatim> __parameters__ | *state* | it int, it is WebCacheDB.VersionReadyState, if string, it is the version string. | ---++++ !ManagedResourceStore:GetUpdateInfo Retrieves the update info for this store * _param_ __return__ : status, last_time, manifest_date_header, update_error __syntax__ <verbatim>function ManagedResourceStore:GetUpdateInfo() </verbatim> ---++++ !ManagedResourceStore:SetUpdateInfo Sets the update info for this applicaiton __syntax__ <verbatim>function ManagedResourceStore:SetUpdateInfo(status, last_time, manifest_date_header, update_error) </verbatim> __parameters__ | *status* | | | *last* | | | *time* | | | *manifest* | | | *date* | | | *header* | | | *update* | | | *error* | | ---++ creating instances of local servers | *Title* | creating instances of local servers | | *Author(s)* | LiXizhi | | *Date* | 2008/2/27 | | *File* | script/kids/3DMapSystemApp/localserver/factory.lua | ---+++ Description %T% __Sample Code__ <verbatim> NPL.load("(gl)script/kids/3DMapSystemApp/localserver/factory.lua"); local store = Map3DSystem.localserver.CreateStore("WebserviceStore_sample", 2) local store = Map3DSystem.localserver.CreateStore("ResourceStore_sample", 1) local store = Map3DSystem.localserver.CreateStore("ManagedResourceStore_sample", 0) </verbatim> ---+++ Member Functions ---++++ !Map3DSystem.localserver.GetStore get the loaded store. if the store is not loaded,it will return nil. To CreateGet a store, use CreateStore() instead. __syntax__ <verbatim>function Map3DSystem.localserver.GetStore(name)</verbatim> __parameters__ | *name* | | ---++ cache policy | *Title* | cache policy | | *Author(s)* | LiXizhi | | *Date* | 2008/3/2 | | *File* | script/kids/3DMapSystemApp/localserver/cache_policy.lua | ---+++ Description In NPL local server, there is a single cache policy which is slight different from standard HTTP cache (The official version is here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9) ---++ NPL local server caching policy The cache policy by NPL local server (and represented by this CachePolicy class) is stated below: * find the entry in the local server. If a completed entry is found, it is always returned immediately, regardless of whether it has expired or not. * if no entry is found or the entry expired, a new entry will be fetched via remote server and updated in the local server. * When a entry is updated in the store, it will be returned to all callback functions registered to it. __Note1__: It means that the same request might be returned twice. The first time is the local version at the time of call; and the second time is when the entry is just updated via the server. The second call is skipped if the server can verify that the content has not changed and only update the last access time in the local store. __Note2__: If the relative expire time is 0, the first call is ignored. __Note3__: If the relative expire time is larger than a year, the second call is always ignored. __Note4__: This same policy applies to ResourceStore, ManagedResourceStore, and WebserviceStore.For WebserviceStore, only access base time type is permitted. The server policy can be overwritten by local server policy, local server policy can be overwritten by per function policy To increase efficiency, one can create several different cache policy objects and share them for all local stores and related function calls. %T% __Sample Code__ <verbatim> NPL.load("(gl)script/kids/3DMapSystemApp/localserver/cache_policy.lua"); local cache_policy = Map3DSystem.localserver.CachePolicy:new("access plus 1 month"); cache_policy:IsExpired(ParaGlobal.GetSysDateTime()-80000); -- there are some premade policies, which can be retrieve from Map3DSystem.localserver.CachePolicies, see below local cp = Map3DSystem.localserver.CachePolicies["never"]; local cp = Map3DSystem.localserver.CachePolicies["always"]; local cp = Map3DSystem.localserver.CachePolicies["1 hour"]; local cp = Map3DSystem.localserver.CachePolicies["1 day"]; </verbatim> ---+++ Member Functions ---++++ !CachePolicy:new <verbatim>-------------------------- CachePolicy class -------------------------- local CachePolicy = { -- The base time is either the last modification time of the file, or the time of the client's access to the document. -- 0 means that the file's last modification time should be used as the base time, -- 1 means the client's access time should be used. -- nil Expiration is not enabled. BaseTime = 1, -- Time in seconds to expire relative to BaseTime. e.g. 2592000 is a month, which is good for asset and images. 604800 is a week which is good for profile and content pages. ExpireTime = 604800, }</verbatim>; commonlib.setfield("Map3DSystem.localserver.CachePolicy", CachePolicy); create the object and init from initCode. format of initCode, please see Init() function. __syntax__ <verbatim>function CachePolicy:new(initCode)</verbatim> __parameters__ | *initCode* | | ---++++ !CachePolicy:Init [[ Extacts the policy base time type expire time from an input string. * _param_ __initCode__ : string: it has the following syntax "<base> [plus] {<num> <type>}*" where <base> is one of: access, now (equivalent to 'access'), modification The plus keyword is optional <num> should be an integer value, and <type> is one of: years months weeks days hours minutes seconds For example, any of the following can be used to make entries expire 1 month after being accessed: - "access plus 1 month" - "access plus 4 weeks" - "access plus 30 days" The expiry time can be fine-tuned by adding several '<num> <type>' clauses: - "access plus 1 month 15 days 2 hours" - "modification plus 5 hours 3 minutes" * _return_ ____ : Returns true if successful. ]] __syntax__ <verbatim>function CachePolicy:Init(initCode)</verbatim> __parameters__ | *initCode* | string: it has the following syntax "<base> [plus] {<num> <type>}*" where <base> is one of: access, now (equivalent to 'access'), modification The plus keyword is optional <num> should be an integer value, and <type> is one of: years months weeks days hours minutes seconds For example, any of the following can be used to make entries expire 1 month after being accessed: - "access plus 1 month" - "access plus 4 weeks" - "access plus 30 days" The expiry time can be fine-tuned by adding several '<num> <type>' clauses: - "access plus 1 month 15 days 2 hours" - "modification plus 5 hours 3 minutes" | ---++++ !CachePolicy:IsExpired whether time is expired. * _param_ __Basetime__ : the base time in second * _return_ ____ : true if input time is expired __syntax__ <verbatim>function CachePolicy:IsExpired(Basetime)</verbatim> __parameters__ | *Basetime* | the base time in second | ---++++ !CachePolicy:IsCacheEnabled * _return_ __whether__ : cache is enabled. i.e. self.ExpireTime is not 0. __syntax__ <verbatim>function CachePolicy:IsCacheEnabled()</verbatim> __parameters__ | *return* | cache is enabled. i.e. self.ExpireTime is not 0. | ---++++ !CachePolicy:IsCacheAlwaysUsed * _return_ __whether__ : cache is always used. i.e. self.ExpireTime over 1 year. __syntax__ <verbatim>function CachePolicy:IsCacheAlwaysUsed()</verbatim> __parameters__ | *return* | cache is always used. i.e. self.ExpireTime over 1 year. | %STOPINCLUDE%
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2008-02-29
-
LiXizhi
Home
Site map
CCWeb web
HaqiTeen web
Main web
ParaEngine web
TWiki web
Main Web
Users
Groups
Index
Search
Changes
Notifications
RSS Feed
Statistics
导航页WebTopMenu
Preferences
开发指南
Getting Started
ParacraftSDK
NPL
MCML
NPL Reference Manual
美术Mod
Account
Log In
English
简体中文
簡體中文
E
dit
A
ttach
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback