openVXI的缓存实现机制
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
DocumentParser的FetchDocument方法的声明如下:
int DocumentParser::FetchDocument(const VXIchar * url,
const VXIMapHolder & properties,
VXIinetInterface * inet,
VXIcacheInterface * cache,
SimpleLogger & log,
VXMLDocument & document,
VXIMapHolder & docProperties,
bool isDefaults,
bool isRootApp,
VXIbyte **content,
VXIulong *size);
很明显声明用到了VXIcacheInterface,但是继续阅读代码,却没有发现使用了参数cache。就是参数中虽有VXIcacheInterface,但是函数中并没有用到。浏览一下函数FetchDocument,里面有这样的注释:
// (1) Load the VXML DTD for validation. This will override an externally
// specified DTD if the user provides a link.
// (2) Load the url into memory.
// (3) Pull the document from cache.
// (4) Not in cache; parse buffer into our VXML document representation
// (5) Write the compiled form out to the cache.
// (6) Parse was successful, process document. W e want only the top level
看一下// (3) Pull the document from cache.下面的代码,会发现是从一个叫DocumentStorageSingleton的变量里面。
DocumentStorageSingleton::Instance()->Retrieve(doc, buffer, bufSize, docURL.c_str())
看一下DocumentStorageSingleton里面有个成员变量DOC_STORAGE storage;其实是map类型的。注释所指的cache就是DocumentStorageSingleton。也就是说DocumentParser用到的cache的功能是由DocumentSt orageSingleton实现的。
看一下VXIcache.h开头的注释:
/* Abstract interface for accessing caching functionality, which
* permits writing arbitrary data into the cache with a client
* supplied key name, then retrieving that data from the cache one or
* more times by reading against that key name.
*
* Normally the cache implementation can choose to discard the data
* between the write and the read when necessary (due to running out
* of cache space, etc.), but it is also possible for clients to lock
* data in the cache to support built-in grammars and other data that
* is explicitly provisioned by system administrators and thus must
* not be removed unless by explicit system administrator command.
* The interface is a synchronous interface based on the ANSI/ISO C
* standard file I/O interface. The client of the interface may use this in
* an asynchronous manner by using non-blocking I/O operations,
* creating threads, or by invoking this from a separate server
* process.
*
* Typically the key name specified by clients will be the URL to the
* source form of the data that is being written back, such as the URL
* to the grammar text being used as the key name for the compiled
* grammar. In the case where the VXIinet and VXIcache implementations
* share the same underlying cache storage, it is thus necessary to
* use prefixes or some other namespace mechanism to avoid collisions
* with the cache entry for the original URL.
*
* However, the key names specified by clients may be very large in
* some cases. This is most common when writing back data generated
* from in-memory source text, such as when writing back the compiled
* grammar for a VoiceXML document in-line grammar. One possible
* VXIcache implementation approach is to use the MD5 algorithm as
* used in HTTP message headers (specified in RFC 1321 with a full
* implementation provided) to convert long key names to a 16 byte MD5
* value for indexing purposes, using Base64 encoding to convert the
* binary MD5 value to ASCII text if desired (as done in HTTP message
* headers).
*
* There is one cache interface per thread/line.
*/
大意是说可以放进去任意的数据,并可以用URL检索出来。URL如果太长,会用md5和base64处理。那c ache模块中的功能在那儿用到了那?在VXIclient.cpp的第1088行(左右)有下面的内容:
/* Create the cache resource. The cache resource will be used by
the recognizer and prompting components for caching of computed
data like compiled grammars and text-to-speech prompts. */
cacheResult = SBcacheCreateResource(newPlatform->VXIlog, &newPlatform->VXIcache);
注释的意思是cache是recognizer和prompting 组件用到的。在VXIprompt和VXIrec中,仅仅有VXIpromptResult VXIpromptCreateResource (
VXIlogInterface *log,
VXIinetInterface *inet,
VXIcacheInterface *cache,
VXIpromptInterface **prompt)
和
VXIREC_API VXIrecResult VXIrecCreateResource(VXIlogInterface *log,
VXIinetInterface *inet,
VXIcacheInterface *cache,
VXIpromptInterface *prompt,
VXItelInterface *tel,
VXIrecInterface **rec)
用到了,而且函数里面参数cache并没有用到,感觉要实现者自己写代码吧。代码没再继续往下看。