Model-Glue Viewデータのキャッシング

topica.comのModel-GlueのMLで、'Caching Content in MG'というタイトルでコンテンツのキャッシングに関するスレッドが立った。

解決方法は、ズバリ・・・
ModelGlue.Core.controller.cfc内のGetFromCache

ModelGlue.Util.TimedCache.cfc内のItemNotFound

ModelGlue.Core.controller.cfc内のAddToCache
を使う。つまり、
1.キャッシュしたいコンテンツ<"news">を定義し、
 <cftry>

   <cfset news =GetFromCache("news") />
2.次に、キャッシュの有無をチェックし、
   <cfcatch type="ModelGlue.Util.TimedCache.ItemNotFound">
3.例外が生じた場合、特定の処理を実施し、キャッシュに追加

     something query
     <cfset addToCache("news", news) />

       <cfcache />

  </cftry>

するようだ。

<cffunction name="GetNews" access="Public" returnType="void"
output="false" hint="I am an event handler.">
  <cfargument name="event" type="ModelGlue.Core.Event" required="true">

  <cfset var news = "" />

  <cftry>
    <!--- Try to get it from the cache --->
    <cfset news = getFromCache("news") />
    <!--- If it's not in the cache --->
    <cfcatch type="ModelGlue.Util.TimedCache.ItemNotFound">
      <cfquery datasource="foo" name="news">
        SELECT newsId, title FROM news
      </cfquery>
      <cfset addToCache("news", news) />
    </cfcatch>
  </cftry>

  <cfset arguments.event.setValue("news", news) />
</cffunction>

うーん、やはりModelGlueの内部をもう少し学ぶ必要がありそうだなあー。

 

CFMX開発 | ModelGlue
2005/08/02 22:48



コメント

コメントを見る (0)

コメントを投稿

* コメントは記事の投稿者が承認するまで表示されません。