0

andから継承するコントロールを作成したSystem.Web.UI.WebControls.DropDownListので、このコントロールの前にコードはありませんが、OutputCache ディレクティブを設定したいと考えています。属性などを使用して、C#コードでこれを設定する方法はありますか?

VaryByParamプロパティを複製できることを特に望んでいます

4

2 に答える 2

2

これは信じられないほど古い質問だと思いますが、それでも答える価値があります。

あなたが話しているのはユーザーコントロールではなく、カスタムコントロールです。OutputCache でやりたいことは、Context Cache で簡単に実行できます。

データを取得して DropDownList にバインドするコードでは、次のようにします。

        List<Object> listOfObjects = null;
//assuming a List of Objects... it doesn't matter whatever type of data you use
        if (Context.Cache["MyDataCacheKey"] == null)
        {
            // data not cached, load it from database
            listOfObjects = GetDataFromDB();
//add your data to the context cache with a sliding expiration of 10 minutes.
            Context.Cache.Add("MyDataCacheKey", listOfObjects, null,
                System.Web.Caching.Cache.NoAbsoluteExpiration,
                TimeSpan.FromMinutes(10.0),
                System.Web.Caching.CacheItemPriority.Normal, null);
        }
        else
            listOfObjects = (List<Object>)Context.Cache["MyDataCacheKey"];

        DropDownList1.DataSource = listOfObjects;
        DropDownList1.DataBind();
于 2010-07-15T18:14:40.667 に答える
1
Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetCacheability(HttpCacheability.Server);
Response.Cache.SetValidUntilExpires(true);
于 2008-09-17T01:41:24.467 に答える