私はウェブプロジェクトに取り組んでいます。データを保存したい (WCFservice から)。次に、クライアントからリクエストが来たときに、データベースの値が変更されているかどうかを確認したいと思います。私はWCFメソッドを介してこのチェックを行っています。キャッシュ データの時間フィールドが WCF メソッドからの時間値と等しくない場合、コードは WCF メソッドを呼び出してデータベースから新しいデータを取得する必要があります。新しいデータはキャッシュに保存され、ページにも表示されます。
Noooow... :/ プロジェクトを実行して xxx ページを表示し、別のページを表示してから、xxx ページを再表示します。私のデータ(キャッシュに保存されている)は絶対に、本当に、非常にNULLです...コードはここにあります:私はあなたの完璧な提案の人々を聞いて本当にうれしいです. なぜnullにする必要があるのですか、どうすればキャッシュから取得できますか。1番目の方法はwcfにあり、2番目の方法はすでに問題のあるページのロードです
public MeasurementSystemPageWcf GetActiveSystemMeasurementPage(bool RequestOnlyInfo)
{
Session session = DBUtil.GetSession();
XPClassInfo MeasurementSystemPageClass = session.GetClassInfo(typeof(MeasurementSystemPage));
string QCriteria = "ISACTIVE =='true'";
CriteriaOperator criteria = CriteriaOperator.Parse(QCriteria);
SortingCollection sortProps = new SortingCollection(null);
sortProps.Add(new SortProperty("", SortingDirection.Ascending));
CollectionCriteriaPatcher patcher = new CollectionCriteriaPatcher(false, session.TypesManager);
ICollection MeasurementSystemPageCollection = session.GetObjects(MeasurementSystemPageClass, criteria, sortProps, 0, patcher, true);
MeasurementSystemPageWcf RetVal = new MeasurementSystemPageWcf();
if (MeasurementSystemPageCollection != null && MeasurementSystemPageCollection.Count != 0)
{
if (!RequestOnlyInfo)
{
foreach (MeasurementSystemPage item in MeasurementSystemPageCollection)
{
// sadece bir tane aktif sayfa gelmesi gerektiği varsayılarak kolleksiyondaki ilk sayfa alınacak. break ile sağlanıyor
RetVal.PAGEHEADER = item.PAGEHEADER;
RetVal.CONTENT = item.CONTENT;
RetVal.CREATEDATE = item.CREATEDATE;
RetVal.EDITDATE = item.EDITDATE;
break;
}
}
else if (RequestOnlyInfo)
{
foreach (MeasurementSystemPage item in MeasurementSystemPageCollection)
{
// sadece bir tane aktif sayfa gelmesi gerektiği varsayılarak kolleksiyondaki ilk sayfa alınacak. break ile sağlanıyor
RetVal.EDITDATE = item.EDITDATE;
break;
}
}
}
else
{
RetVal.ER.HasError = true;
RetVal.ER.ErrorMethod = "MeasurementSystemPageWcf GetActiveSetMeasurementPage()";
RetVal.ER.ErrorMessage = "Henüz İçerik Girilmemiş";
}
return RetVal;
}
protected void Page_Load(object sender, EventArgs e)
{
XSensServiceClient client = new XSensServiceClient();
MeasurementSystemPageWcf page_in_cache = (MeasurementSystemPageWcf)Cache["MeasurementSystemPage"];
if (page_in_cache == null)
{
MeasurementSystemPageWcf active_page = client.GetActiveSystemMeasurementPage(false);
if (active_page.ER.HasError)
{
lbl_Body.Text = active_page.ER.ErrorMessage;
Page.Title = active_page.ER.ErrorMessage;
}
else
{
Cache.Insert("MeasurementSystemPage", active_page, null, DateTime.Now.AddDays(7), TimeSpan.Zero, CacheItemPriority.NotRemovable, null);
//Cache["MeasurementSystemPage"] = active_page;
Page.Title = active_page.PAGEHEADER;
lbl_Body.Text = active_page.CONTENT;
}
}
else
{
MeasurementSystemPageWcf active_page_from_wcf = client.GetActiveSystemMeasurementPage(true); // buraya sadece edit zamanını çeken bir method yazılacak, her karşılaştırmada bütün sayfa verisini çekmemek için.
MeasurementSystemPageWcf active_page_from_cache = (MeasurementSystemPageWcf)Cache["MeasurementSystemPage"];
if (active_page_from_cache.EDITDATE < active_page_from_wcf.EDITDATE)
{
MeasurementSystemPageWcf updated_page = client.GetActiveSystemMeasurementPage(false);
Cache.Insert("MeasurementSystemPage", updated_page, null, DateTime.Now.AddDays(7), TimeSpan.Zero, CacheItemPriority.NotRemovable, null);
Page.Title = updated_page.PAGEHEADER;
lbl_Body.Text = updated_page.CONTENT;
}
else
{
Page.Title = active_page_from_cache.PAGEHEADER;
lbl_Body.Text = active_page_from_cache.CONTENT;
}
}
web.config は次のとおりです。
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="devExpress">
<section name="themes" type="DevExpress.Web.ASPxClasses.ThemesConfigurationSection, DevExpress.Web.v13.1, Version=13.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false"/>
<section name="compression" type="DevExpress.Web.ASPxClasses.CompressionConfigurationSection, DevExpress.Web.v13.1, Version=13.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false"/>
<section name="settings" type="DevExpress.Web.ASPxClasses.SettingsConfigurationSection, DevExpress.Web.v13.1, Version=13.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false"/>
<section name="errors" type="DevExpress.Web.ASPxClasses.ErrorsConfigurationSection, DevExpress.Web.v13.1, Version=13.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" requirePermission="false"/>
</sectionGroup>
</configSections>
<system.web>
<!--caching nodu sonradan eklendi-->
<caching>
<cache disableExpiration="true"/>
</caching>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="DevExpress.Web.v13.1, Version=13.1.6.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
<add assembly="DevExpress.Data.v13.1, Version=13.1.6.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="DevExpress.RichEdit.v13.1.Core, Version=13.1.6.0, Culture=neutral, PublicKeyToken=B88D1754D700E49A"/>
</assemblies>
</compilation>
<httpModules>
<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v13.1, Version=13.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule"/>
</httpModules>
<httpHandlers>
<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v13.1, Version=13.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="DX.ashx" validate="false"/>
</httpHandlers>
<pages>
<controls>
<add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit"/>
</controls>
</pages>
</system.web>
<system.webServer>
<modules>
<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v13.1, Version=13.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" name="ASPxHttpHandlerModule"/>
</modules>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<add type="DevExpress.Web.ASPxClasses.ASPxHttpHandlerModule, DevExpress.Web.v13.1, Version=13.1.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" verb="GET,POST" path="DX.ashx" name="ASPxHttpHandlerModule" preCondition="integratedMode"/>
</handlers>
</system.webServer>
<devExpress>
<themes enableThemesAssembly="true" styleSheetTheme="" theme="" customThemeAssemblies=""/>
<compression enableHtmlCompression="false" enableCallbackCompression="true" enableResourceCompression="true" enableResourceMerging="true"/>
<settings rightToLeft="false" doctypeMode="Xhtml"/>
<errors callbackErrorRedirectUrl=""/>
</devExpress>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IXSensService" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://127.0.0.1/XSensWCFService/XSENSWCFService.XSensService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IXSensService"
contract="XSensService.IXSensService" name="WSHttpBinding_IXSensService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>