在 Silverlight 中使用企业库缓存应用程序块
我已经下载了图案和实践 Silverlight 集成包 在我的 Silverlight 中使用缓存(缓存应用程序块)应用程序,但我尝试了又尝试,但没有成功。 我没有找到任何有用的例子 - 有人有例子吗?只需几行代码就可以显示简单的用法? 我需要使用统一吗?
谢谢!
我使用了从企业库配置 - 工具中导出为 XAML 的默认配置:
<el:CachingSettings DefaultCache="In-Memory Cache" x:Key="cachingSilverlightConfiguration">
<el:CachingSettings.Caches>
<el:InMemoryCacheData ExpirationPollingInterval="00:02:00" Name="In-Memory Cache" />
</el:CachingSettings.Caches>
</el:CachingSettings>
当我尝试使用以下代码访问它时:
ObjectCache cache = EnterpriseLibraryContainer.Current.GetInstance<ObjectCache>("In-Memory Cache");
然后,我收到异常:
{System.IO.FileNotFoundException: The system cannot find the file specified. File name: 'System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ...
I have downloaded the patterns & practices Silverlight Integration Pack to use caching (Caching Application Block) in my Silverlight Application, but i tried and tried and didn't get it to work.
I did not find any useful example - does anyone have an example? Just a few lines of code that are showing a simple usage?
Do I need to use unity?
THANKS!
I used a default configuration that i got from the Enterprise Library Configuration - Tool which i exported as XAML:
<el:CachingSettings DefaultCache="In-Memory Cache" x:Key="cachingSilverlightConfiguration">
<el:CachingSettings.Caches>
<el:InMemoryCacheData ExpirationPollingInterval="00:02:00" Name="In-Memory Cache" />
</el:CachingSettings.Caches>
</el:CachingSettings>
And when I try to access it with the following code:
ObjectCache cache = EnterpriseLibraryContainer.Current.GetInstance<ObjectCache>("In-Memory Cache");
then, i get an Exception:
{System.IO.FileNotFoundException: The system cannot find the file specified. File name: 'System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 Entlib 支持的 Randy Levy,我得到了 我需要的答案,在那里:
看起来您还没有配置容器。如果您不想调用服务器来检索配置,那么您需要嵌入并加载配置。
或者,如果您不想在代码中包含该字符串,但更喜欢在 XAML 文件中,请确保 XAML 文件(例如cacheConfig.xaml)的构建操作是嵌入资源,然后您可以使用以下代码:
SilverlightApplicationCache<上面的 /code> 是 XAML 文件的命名空间(例如项目的默认命名空间)。
Thanks to Randy Levy from the Entlib Support, I got the answer I needed, there:
It looks like you haven't configured the container. If you don't want to call to the server to retrieve the configuration then you need to embed and load the configuration.
Or if you don't want to have the string in the code but prefer in a XAML file then ensure the XAML file's (e.g. cacheConfig.xaml) Build Action is Embedded Resource and then you can use the following code:
SilverlightApplicationCache
above is the namespace of the XAML file (eg. the default namespace of the project).