C# - Cache XmlTextWriter Data?
Dec 22, 2010
I have a page where I'm just writing a bunch of XML data to the screen. It's making several database calls to get all the data:
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
writer.WriteStartDocument();
writer.WriteStartElement("rss");
[code]...
View 4 Replies
Similar Messages:
Mar 11, 2010
I am using the xmltextwriter and having issues with opening tags not showing if the field is blank here is the start of my code
Code:
Dim strFilePath As String = Server.MapPath("../test.xml")
Dim utf8 As Encoding = New UTF8Encoding(False)
Dim objWriter As XmlTextWriter = New XmlTextWriter(strFilePath, New UTF8Encoding(False))
' start writing the XML document
objWriter.WriteStartDocument()
Try
conn.Open()
myreader = cmd.ExecuteReader
objWriter.WriteStartElement("testfile")
While myreader.Read
output the first "product" element
objWriter.WriteStartElement("product", Nothing)
objWriter.WriteElementString("Id", myreader("rvid").ToString)
objWriter.WriteElementString("Class", myreader("RVClass").ToString)
objWriter.WriteElementString("Manu", myreader("rvmanu").ToString)
objWriter.WriteElementString("Model", myreader("rvmake") & " " & myreader("rvmodel"))
objWriter.WriteElementString("Year", myreader("rvyear").ToString)
objWriter.WriteElementString("Price", myreader("rvcashprice").ToString)
objWriter.WriteElementString("NU", myreader("rvnu").ToString)
objWriter.WriteElementString("SCapacity", myreader("rvcapacity").ToString)
objWriter.WriteElementString("Fuel", myreader("rvfuel").ToString)
objWriter.WriteElementString("Length", myreader("rvlenft").ToString)
objWriter.WriteElementString("Air", myreader("rvair").ToString)
objWriter.WriteElementString("Awnings", myreader("rvawnings").ToString)
Thats not all of it.. but what happens is if it is blank value Then i get this, as you see fuel has no opening tags, and the company i am supplying to needs these.
<Price>0.0000</Price>
<NU>U</NU>
<SCapacity>0</SCapacity>
<Fuel />
<Length>0</Length>
What can i do to make this work how i want? I though the .tostring woudl fix it but it didnt.
View 4 Replies
Mar 10, 2010
I have this code for the settings:
Dim settings As XmlWriterSettings = New XmlWriterSettings()
settings.Indent = True
settings.OmitXmlDeclaration = True
settings.NewLineOnAttributes = True
Then I have this code for the writer:
Dim xml As New XmlTextWriter(Server.MapPath("output.xml"), enc)
Please can you tell me how I make the settings apply to the writer?EDIT: Code sample
Sub writexml_OnClick(ByVal sender As Object, ByVal e As EventArgs)
Try
'Vars
[code]...
View 2 Replies
Aug 1, 2010
We have a data driven ASP.NET website which has been written using the standard pattern for data caching (adapted here from MSDN):
public DataTable GetData()
{
string key = "DataTable";
object item = Cache[key] as DataTable;
[code]...
The trouble with this is that the call to GetDataFromSQL() is expensive and the use of the site is fairly high. So every five minutes, when the cache drops, the site becomes very 'sticky' while a lot of requests are waiting for the new data to be retrieved.
What we really want to happen is for the old data to remain current while new data is periodically reloaded in the background. (The fact that someone might therefore see data that is six minutes old isn't a big issue - the data isn't that time sensitive). This is something that I can write myself, but it would be useful to know if any alternative caching engines (I know names like Velocity, memcache) support this kind of scenario. Or am I missing some obvious trick with the standard ASP.NET data cache?
View 3 Replies
Sep 13, 2010
I have use Nhibernate in my MVC Project by me known, Nhibernate have cache on Session and Object. now, I want use HttpContext.Current.Cache (system.web) for cache data something in project. my code same that have problem, haven't it. and that's right or wrong.
View 2 Replies
Mar 29, 2010
Is it correct to implement my caching object like this in my controller :
[code]....
And I Use it like this :
[code]....
View 1 Replies
Feb 25, 2011
We have a wfc layer that wraps the business classes and database access and use a client that lives on the database layer. Amongst our group we are attempting to form standards. Some want to have the client call the web method and pass the page they are requesting and the page size. Pass that to the database and then page in SQL Server use RowNum.Some want to cache the full list of objects in http cache on the service tier and page in memory. They concern here is memory use on the server.
Which would be best for a medium number of users with potentially large number of records to manage (say 30K) Is it better to cache them all in memory and work from there or page at the database as the application scales?
View 1 Replies
Jul 28, 2010
What are the "optimal" parameters for creating an AppFabric cache when you will be storing session state in the cache? MSDN Cache-Related Commands
Powershell command line:
New-Cache [-CacheName] <String> [-Eviction <String>] [-Expirable <String>] [-Force [<SwitchParameter>]] [-NotificationsEnabled <String>] [-Secondaries <Int32>] [-TimeToLive <Int64>]
[code]...
Since I don't want my sessions to be removed unless the session has been abandoned either via code or Session Timeout...For eviction, I would think "None" and for expireable, I would think False.I have tested and calling Session.Abandon does remove the object from the cache. I have also tested to see if by extending my session, the session object in cache is also extended. This does seem to work the "correct" way.
View 1 Replies
Feb 24, 2010
We are using HttpRuntime.Cache API in an ASP.NET to cache data retrieved from a database.
For this particular application, our database queries feature a LOT of parameters, so our cache keys look something like this:
table=table1;param1=somevalue1;param2=somevalue2;param3=somevalue3;param4=somevalue4;param5=somevalue5;param6=somevalue6... etc...
we have so many parameters that the cache key is several hundred characters long. is there a limit to the length of these cache keys? Internally, it is using a dictionary, so theoretically the lookup time should be constant. However, I wonder if we have potential to run into some performance/memory problem.
View 1 Replies
Feb 26, 2010
I've got a web application that runs of a state server. It looks like soon it may need to distributed and there will be two web servers behind a load balancer.
This works great for session state but my next challenge is Cache
My application leverages heavily of cache. I understand ASP.Net 4.0 will be offering more here but nothing much has been said about the how too.
There are two challenges that I face
1). Each webserver will have its own copy of cache whereas it would be more efficient to put this to a third server the same as session state is put to state server.
2). The real challenge is keeping cache in sync if a simple dataset derived from the database is changed my code dumps that cache item and reloads the cache. That's all well on one webserver but webserver number two wont know to drop that particular cache item and reload it. This could cause some unexpected problems in the application.
For scenario number 2 I could attempt to do some smart coding so server number two knows to dump the cache and reload it.
My guess is someone else has already been here before and there's probably a better implementation approach rather than writing extra code.
Does anyone know how I could achieve the goal of keeping Cache in sync between multiple webservers or even better farm Cache management to another server?
View 2 Replies
Nov 2, 2010
I need to enable caching in my asp.net application, but I do not want to use the webserver's memory for holding cache objects. If I add the page directive for output caching will the page be stored in the asp.net cache object?
View 2 Replies
Dec 12, 2010
I want to be able to maintain certain objects between application restarts.
To do that, I want to write specific cached items out to disk in Global.asax Application_End() function and re-load them back on Application_Start().
I currently have a cache helper class, which uses the following method to return the cached value:
return HttpContext.Current.Cache[key];
Problem: during Application_End(), HttpContext.Current is null since there is no web request (it's an automated cleanup procedure) - therefore, I cannot access .Cache[] to retrieve any of the items to save to disk.
Question: how can I access the cache items during Application_End()?
View 4 Replies
Jan 14, 2010
Im building a image gallery which reads file from disk, create thumbnails on the fly and present them to the user. This works good, except the processing takes a bit time.
I then decided to cache the processed images using the ASP .NET Application Cache. When a image is processed I add the byte[] stream to the cache. As far as I know this is beeing saved into the system memory. And this is working perfect, the loading of the page is much faster.
My question is if there are thousands of images which gets cached in the Application Cache, will that affect the server performance in any way?
View 3 Replies
Oct 28, 2010
You know I have the way to Cache the data I've got from the SQL Server over data caching. In addition I can output cache web user controls.Whats about a web user control contains data from a SQL database? Does it make sense to cache the data and also cache the control?What is the best solution for the combination of these two components?
View 1 Replies
Feb 11, 2011
I have a server control that I developed which generates navigation based on a third party CMS API. Currently I am caching this control using the PartialCaching attribute. The CMS uses cache key dependencies to invalidate the cache when a user makes an edit, however in the case of my server control it does not get invalidated and the updated navigation will not show up until the cache expiration set by the PartialCaching attribute.Here is my two part question:
What is the proper way to programmatically cache a server control, without using the PartialCaching attribute, and adding a cache key dependency?
Is it possible to continue to use the PartialCaching attribute and add a cache key dependency?
View 2 Replies
Feb 17, 2010
I am embarrassed to ask, but what is the best way to add key/value pair data in cache (HttpRuntime.Cache) to a DataTable?
I'm currently dumping the key/value pair data from cache into a HashTable, which becomes the DataSource for a Repeater object. Unfortunately, I cannot sort the data in the Hashtable and therefore thought a DataTable (being the DataSource for the Repeater) would solve my dilema.
View 5 Replies
Feb 27, 2011
I want to implement caching of a list pulled from the db. I've had a look at this:
How can I cache objects in ASP.NET MVC?
I have this in my code:
var addresses = repository.GetAllAddresses();//returns IQueryable<string>
using the answer in the question above how can i cache this?, I have created the class CacheExtensions, but not sure where to go from there.
View 1 Replies
Feb 22, 2011
There are asp files already running on (Production server)the windows 2000 iis webserver. Recently we had done changes and we deployed the changes on the production server. when we try to browse the url it shows the older data. not he changed data. Afer that i clear my browser cache then i tried, it worked as expected i could see the recen changes on the screen.
But some time i oculd see the recen changes and some time i couldn't see the cahnges. it shows the older details. I knew this is because of Cache issue.
every time we cannot clear the cache and run. because we have users more then 2000. so we cannot ask all of them to clear the cache and try.
Details:
File type : asp
Server : Windows 2000
IIS version : 6.0
View 5 Replies
Feb 1, 2011
If I store all my user info, upon login, in cache and just have a "my account" page that displays the user info from cache, is that a good practice? I'm wondering if a person changes his email or does any type of database modification then the cached variables will be the wrong ones. If I have to update the cache variables every time something happens to the database, is this even a good practice compared to just querying the data whenever needed?
View 3 Replies
Nov 10, 2010
I'm using the OutputCache for my pages, and I have a dynamic user control (login/register) . When the user try to sign in, the the control do not change the aspect because I´m using OutputCache. How can I exclude the "login/register" control from the cache?
View 6 Replies
Mar 15, 2011
I have a master/detail web form and i have implement a caching to hold detail data. i am facing problem that when two user login same time and enter data, cache has combined the data and both user ara getting each other data. i want every user gat his own data.
View 6 Replies
Feb 24, 2011
I am creating a graphical tool in silverlight which reads data from multiple files and database.
i dont want to call the database again and again. i want to retrieve the data when required and keep it safe somewhere so if the user or any other user visits the same page, they can then access the data.
i want to use application state of asp.net Cache["Object"] but in Silverlight? what is the best methodolgy?
View 3 Replies
Sep 13, 2010
I'm trying to build a process that will repopulate an item that was inserted into cache every 30 minutes. I inserted the item into Cached to expire after 30 minutes. I setup a delegate (http://msdn.microsoft.com/en-s/library/system.web.caching.cacheitemremovedcallback(v=VS.90).aspx) to be called when the cached item expired. My goal was when the delegate was called was to rebuild the item and insert it back into cached. The issue I found with the MSDN article above was that it was using a holding the page instance open until the delegate was called. Instead of had it call another class that was static (vb shared). This caused a different problem -- the delegate lost context. When I tried to add back into the cache the HttpContext.Current was null. Is there a way I can repopulate an item in cache every 30 minutes in ASP.NET without keeping page instances around? Note, I cannot use a sliding expiration date because the content will change.
View 1 Replies
Jun 9, 2010
I have a weired problem. One of the pages in my application show's status of tasks in a table. I am using entity framework ( entity to object) to do all the data handling with DB. I noticed that even though the status is updated in DB, its not reflected on my webpage even after continuous refresh! If i stop the server and start the application again (currently running on VS2008 dev server) the updated data is displayed!
Am I seeing the cached data? how do I prevent this from happening?
View 1 Replies
Jun 3, 2010
I have the following .NET VB code to set and read objects in cache on a per user basis (i.e. a bit like session)
'' Public Shared Sub CacheSet(ByVal Key As String, ByVal Value As Object)
Dim userID As String = HttpContext.Current.User.Identity.Name
HttpContext.Current.Cache(Key & "_" & userID) = Value
End Sub
Public Shared Function CacheGet(ByVal Key As Object)
Dim returnData As Object = Nothing
Dim userID As String = HttpContext.Current.User.Identity.Name
returnData = HttpContext.Current.Cache(Key & "_" & userID)
Return returnData
End Function
I use these functions to hold user data that I don't want to access the DB for all the time. However, when the data is updated, I want the cached item to be removed so it get created again.
How do I make an Item I set disappear or set it to NOTHING or NULL?
View 1 Replies