Caching to an Application Variable, and Performance Issues

  • Thread starter Greg Collins [MVP]
  • Start date
G

Greg Collins [MVP]

Hi, I couldn't find what I was looking for by searching the newsgroup, but perhaps these have already been discussed somewhere. This is a bit long with a lot of interrelated questions.

What I've got is a decodeImage.aspx page that gets called to decode base64 encoded images and return them as displayable images to a Web page. The ASPX page is passed two parameters, "file" and "img". The "file" parameter specifies and XML file on the Web server that contains data including base64 encoded images. The "img" parameter specifies an index to identify which image should be encoded and returned. There could be any number of images to be decoded in the XML file, and their size is also uncertain.

My concern is that if a particular page calls this decodeImage.aspx page numerous times that I am wasting valuable time and efforts by having the XML file loaded each and every time. If I am wrong and this file is not reloaded each time, please let me know, but it's my understanding it will be loaded each time.

So what I was thinking was to cache as an Application variable in the XmlNodeList that was populated with a call to SelectNodes, and name the variable based on the "file" parameter. Then if I find that the variable already exists, use the cached object instead of reloading. Since these images are used site wide, I didn't think a Session variable was appropriate. There can be any number of XML files used, so there could be any number of Application variables that need to be set.

That seems fairly straightforward, but I have a few concerns with that:
1. Can I store the XmlNodeList object and restore it for use the next time?
a. If not, is there any advantage to storing the XML in the variable over having it reloaded?
2. What is the max size for an Application variable?
3. What is the max size for all Application variables together?
4. What actually happens when that size limit has been reached?
5. Once each image have been decoded, are they cached on the server for the Web page to use, or will the Web page always and forever call in to redecode the image each time?
a. If so, I'd like to know my alternatives.
b. If not, how do I know when to release that variable?
6. How do I find out when the XML file has been updated so that I know to update the Application variable?

I think that about covers it. If I think of anything else related to this scenario, I'll do a followup post.

Thanks ahead of time for your help!
 
K

Kevin Spencer

Hi Greg,

1. Can I store the XmlNodeList object and restore it for use the next time?
a. If not, is there any advantage to storing the XML in the variable
over having it reloaded?

The Application and Application Cache are Collections, pure and simple.
Well, the Cache is a specialized type of Collection, but it is, underneath
the specialization (extra methods, fields, etc) a Collection. They are, in
essence, Name and Object Collections.

As everything in .Net is an object, you can store anything in these
Collections, and use them just as you would any object in any Collection.

The advantage of storing your XML in the Collection is the saving of IO
processing and the processing involved in reading the XML from the file into
an object. So, yes, there is an advantage in terms of performance.

2. What is the max size for an Application variable?

AFAIK, there is no maximum size, other than memory capacity. At least, I've
never run into one. And I have put a LOT of data in the Cache before (dozens
of MB).

3. What is the max size for all Application variables together?

Same as above.

4. What actually happens when that size limit has been reached?

I would imagine an "out of memory" exception, but that's just a guess.

5. Once each image have been decoded, are they cached on the server for the
Web page to use, or will the Web page always and forever call in to redecode
the image each time?
a. If so, I'd like to know my alternatives.
b. If not, how do I know when to release that variable?

If you put them into a Collection, such as Application or Cache, they are
cached. How do you know when to release that variable? Well, it's not a
variable, it's a member object of a Collection. Using the Cache, you can
tell the Cache when to remove the object, or you can remove it yourself. If
these XML documents are needed for the lifetime of the Application, you can
do that as well. No harm done. When the Application ends, the Collection is
automatically released.

6. How do I find out when the XML file has been updated so that I know to
update the Application variable?

You could use a FileSystemWatcher to watch for changes in the folder
containing the files, and have it respond to them. You could even cache the
FileSystemWatcher, so that it resides in the Application and works for the
lifetime of the Application.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Greg Collins [MVP]" <Greg.Collins_AT_InfoPathDev.com> wrote in message
Hi, I couldn't find what I was looking for by searching the newsgroup, but
perhaps these have already been discussed somewhere. This is a bit long with
a lot of interrelated questions.

What I've got is a decodeImage.aspx page that gets called to decode base64
encoded images and return them as displayable images to a Web page. The ASPX
page is passed two parameters, "file" and "img". The "file" parameter
specifies and XML file on the Web server that contains data including base64
encoded images. The "img" parameter specifies an index to identify which
image should be encoded and returned. There could be any number of images to
be decoded in the XML file, and their size is also uncertain.

My concern is that if a particular page calls this decodeImage.aspx page
numerous times that I am wasting valuable time and efforts by having the XML
file loaded each and every time. If I am wrong and this file is not reloaded
each time, please let me know, but it's my understanding it will be loaded
each time.

So what I was thinking was to cache as an Application variable in the
XmlNodeList that was populated with a call to SelectNodes, and name the
variable based on the "file" parameter. Then if I find that the variable
already exists, use the cached object instead of reloading. Since these
images are used site wide, I didn't think a Session variable was
appropriate. There can be any number of XML files used, so there could be
any number of Application variables that need to be set.

That seems fairly straightforward, but I have a few concerns with that:
1. Can I store the XmlNodeList object and restore it for use the next time?
a. If not, is there any advantage to storing the XML in the variable
over having it reloaded?
2. What is the max size for an Application variable?
3. What is the max size for all Application variables together?
4. What actually happens when that size limit has been reached?
5. Once each image have been decoded, are they cached on the server for the
Web page to use, or will the Web page always and forever call in to redecode
the image each time?
a. If so, I'd like to know my alternatives.
b. If not, how do I know when to release that variable?
6. How do I find out when the XML file has been updated so that I know to
update the Application variable?

I think that about covers it. If I think of anything else related to this
scenario, I'll do a followup post.

Thanks ahead of time for your help!
 
B

bruce barker

see inline >> comments:

| Hi Greg,
|
| 1. Can I store the XmlNodeList object and restore it for use the next
time?
| a. If not, is there any advantage to storing the XML in the variable
| over having it reloaded?
|
| The Application and Application Cache are Collections, pure and simple.
| Well, the Cache is a specialized type of Collection, but it is, underneath
| the specialization (extra methods, fields, etc) a Collection. They are, in
| essence, Name and Object Collections.
collections.
if memory usage gets high, entries in the cache will automatically be
removed.

|
| As everything in .Net is an object, you can store anything in these
| Collections, and use them just as you would any object in any Collection.
|
| The advantage of storing your XML in the Collection is the saving of IO
| processing and the processing involved in reading the XML from the file
into
| an object. So, yes, there is an advantage in terms of performance.
|
| 2. What is the max size for an Application variable?
|
| AFAIK, there is no maximum size, other than memory capacity. At least,
I've
| never run into one. And I have put a LOT of data in the Cache before
(dozens
| of MB).
|
| 3. What is the max size for all Application variables together?
|
| Same as above.

|
| 4. What actually happens when that size limit has been reached?
|
| I would imagine an "out of memory" exception, but that's just a guess.
amount of memory asp.net will use (usually 60% of real memory). if asp.net
goes over this number, its recycled (this will lose inproc sessions).

|
| 5. Once each image have been decoded, are they cached on the server for
the
| Web page to use, or will the Web page always and forever call in to
redecode
| the image each time?
| a. If so, I'd like to know my alternatives.
| b. If not, how do I know when to release that variable?
|
| If you put them into a Collection, such as Application or Cache, they are
| cached. How do you know when to release that variable? Well, it's not a
| variable, it's a member object of a Collection. Using the Cache, you can
| tell the Cache when to remove the object, or you can remove it yourself.
If
| these XML documents are needed for the lifetime of the Application, you
can
| do that as well. No harm done. When the Application ends, the Collection
is
| automatically released.
|
| 6. How do I find out when the XML file has been updated so that I know to
| update the Application variable?
|
| You could use a FileSystemWatcher to watch for changes in the folder
| containing the files, and have it respond to them. You could even cache
the
| FileSystemWatcher, so that it resides in the Application and works for the
| lifetime of the Application.
|
on the file, and the cache will release the object automatically if the file
is changed.


| --
| HTH,
| Kevin Spencer
| .Net Developer
| Microsoft MVP
| I get paid good money to
| solve puzzles for a living
|
| "Greg Collins [MVP]" <Greg.Collins_AT_InfoPathDev.com> wrote in message
| | Hi, I couldn't find what I was looking for by searching the newsgroup, but
| perhaps these have already been discussed somewhere. This is a bit long
with
| a lot of interrelated questions.
|
| What I've got is a decodeImage.aspx page that gets called to decode base64
| encoded images and return them as displayable images to a Web page. The
ASPX
| page is passed two parameters, "file" and "img". The "file" parameter
| specifies and XML file on the Web server that contains data including
base64
| encoded images. The "img" parameter specifies an index to identify which
| image should be encoded and returned. There could be any number of images
to
| be decoded in the XML file, and their size is also uncertain.
|
| My concern is that if a particular page calls this decodeImage.aspx page
| numerous times that I am wasting valuable time and efforts by having the
XML
| file loaded each and every time. If I am wrong and this file is not
reloaded
| each time, please let me know, but it's my understanding it will be loaded
| each time.
|
| So what I was thinking was to cache as an Application variable in the
| XmlNodeList that was populated with a call to SelectNodes, and name the
| variable based on the "file" parameter. Then if I find that the variable
| already exists, use the cached object instead of reloading. Since these
| images are used site wide, I didn't think a Session variable was
| appropriate. There can be any number of XML files used, so there could be
| any number of Application variables that need to be set.
|
| That seems fairly straightforward, but I have a few concerns with that:
| 1. Can I store the XmlNodeList object and restore it for use the next
time?
| a. If not, is there any advantage to storing the XML in the variable
| over having it reloaded?
| 2. What is the max size for an Application variable?
| 3. What is the max size for all Application variables together?
| 4. What actually happens when that size limit has been reached?
| 5. Once each image have been decoded, are they cached on the server for
the
| Web page to use, or will the Web page always and forever call in to
redecode
| the image each time?
| a. If so, I'd like to know my alternatives.
| b. If not, how do I know when to release that variable?
| 6. How do I find out when the XML file has been updated so that I know to
| update the Application variable?
|
| I think that about covers it. If I think of anything else related to this
| scenario, I'll do a followup post.
|
| Thanks ahead of time for your help!
|
| --
| Greg Collins [InfoPath MVP]
| Please visit: http://www.InfoPathDev.com
|
|
|
|
 
G

Greg Collins [MVP]

So if I understand you both correctly I could do the following (please excuse my lack of .NET experience and correct anything you need to):

1. The first time the decodeImage.aspx page is hit for a particular XML file, decode the entire list of images, placing each one into an array which is then stored in an Application Cache object in the Cache Collection. This object can be named and referenced using the absolute path of the URL to the XML file being decoded (minus any forbidden characters).

2. I can somehow create a link between the Application Cache object and the XML file itself so that when the XML file is modified, the Cache object is automatically removed from the Collection, thus signaling me to reload the file, decode the images again, and recreate the Cache object.

3. Any subsequent requests for an image would grab the appropriate image from the image array Cache object and return it to the calling Web page.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com


========================================
1. Can I store the XmlNodeList object and restore it for use the next time?
a. If not, is there any advantage to storing the XML in the variable over having it reloaded?

---KEVIN---------------------------
The Application and Application Cache are Collections, pure and simple. Well, the Cache is a specialized type of Collection, but it is, underneath the specialization (extra methods, fields, etc) a Collection. They are, in essence, Name and Object Collections.

As everything in .Net is an object, you can store anything in these Collections, and use them just as you would any object in any Collection.

The advantage of storing your XML in the Collection is the saving of IO processing and the processing involved in reading the XML from the file into an object. So, yes, there is an advantage in terms of performance.

---BRUCE---------------------------
there is one difference between the application cache and the application collections. if memory usage gets high, entries in the cache will automatically be removed.


========================================
2. What is the max size for an Application variable?

---KEVIN---------------------------
AFAIK, there is no maximum size, other than memory capacity. At least, I've never run into one. And I have put a LOT of data in the Cache before (dozens of MB).


========================================
4. What actually happens when that size limit has been reached?

---KEVIN---------------------------
I would imagine an "out of memory" exception, but that's just a guess.

---BRUCE---------------------------
if you look in machine.config/web.config, there is a setting for the max amount of memory asp.net will use (usually 60% of real memory). if asp.net goes over this number, its recycled (this will lose inproc sessions).


========================================
5. Once each image have been decoded, are they cached on the server for the Web page to use, or will the Web page always and forever call in to redecode the image each time?
a. If so, I'd like to know my alternatives.
b. If not, how do I know when to release that variable?


---KEVIN---------------------------
If you put them into a Collection, such as Application or Cache, they are cached. How do you know when to release that variable? Well, it's not a variable, it's a member object of a Collection. Using the Cache, you can tell the Cache when to remove the object, or you can remove it yourself.

If these XML documents are needed for the lifetime of the Application, you can do that as well. No harm done. When the Application ends, the Collection is automatically released.


========================================
6. How do I find out when the XML file has been updated so that I know to update the Application variable?


---KEVIN---------------------------
You could use a FileSystemWatcher to watch for changes in the folder containing the files, and have it respond to them. You could even cache the FileSystemWatcher, so that it resides in the Application and works for the lifetime of the Application.

---BRUCE---------------------------
If you use the application cache object you can place a cache dependency on the file, and the cache will release the object automatically if the file is changed.
 
G

Greg Collins [MVP]

Those steps seemed to work. I have it all implemented and working as I described!

Thank you all for your help! I might not have been able to do it without your knowledge and suggestions!

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



"Greg Collins [MVP]" <Greg.Collins_AT_InfoPathDev.com> wrote in message So if I understand you both correctly I could do the following (please excuse my lack of .NET experience and correct anything you need to):

1. The first time the decodeImage.aspx page is hit for a particular XML file, decode the entire list of images, placing each one into an array which is then stored in an Application Cache object in the Cache Collection. This object can be named and referenced using the absolute path of the URL to the XML file being decoded (minus any forbidden characters).

2. I can somehow create a link between the Application Cache object and the XML file itself so that when the XML file is modified, the Cache object is automatically removed from the Collection, thus signaling me to reload the file, decode the images again, and recreate the Cache object.

3. Any subsequent requests for an image would grab the appropriate image from the image array Cache object and return it to the calling Web page.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com


========================================
1. Can I store the XmlNodeList object and restore it for use the next time?
a. If not, is there any advantage to storing the XML in the variable over having it reloaded?

---KEVIN---------------------------
The Application and Application Cache are Collections, pure and simple. Well, the Cache is a specialized type of Collection, but it is, underneath the specialization (extra methods, fields, etc) a Collection. They are, in essence, Name and Object Collections.

As everything in .Net is an object, you can store anything in these Collections, and use them just as you would any object in any Collection.

The advantage of storing your XML in the Collection is the saving of IO processing and the processing involved in reading the XML from the file into an object. So, yes, there is an advantage in terms of performance.

---BRUCE---------------------------
there is one difference between the application cache and the application collections. if memory usage gets high, entries in the cache will automatically be removed.


========================================
2. What is the max size for an Application variable?

---KEVIN---------------------------
AFAIK, there is no maximum size, other than memory capacity. At least, I've never run into one. And I have put a LOT of data in the Cache before (dozens of MB).


========================================
4. What actually happens when that size limit has been reached?

---KEVIN---------------------------
I would imagine an "out of memory" exception, but that's just a guess.

---BRUCE---------------------------
if you look in machine.config/web.config, there is a setting for the max amount of memory asp.net will use (usually 60% of real memory). if asp.net goes over this number, its recycled (this will lose inproc sessions).


========================================
5. Once each image have been decoded, are they cached on the server for the Web page to use, or will the Web page always and forever call in to redecode the image each time?
a. If so, I'd like to know my alternatives.
b. If not, how do I know when to release that variable?


---KEVIN---------------------------
If you put them into a Collection, such as Application or Cache, they are cached. How do you know when to release that variable? Well, it's not a variable, it's a member object of a Collection. Using the Cache, you can tell the Cache when to remove the object, or you can remove it yourself.

If these XML documents are needed for the lifetime of the Application, you can do that as well. No harm done. When the Application ends, the Collection is automatically released.


========================================
6. How do I find out when the XML file has been updated so that I know to update the Application variable?


---KEVIN---------------------------
You could use a FileSystemWatcher to watch for changes in the folder containing the files, and have it respond to them. You could even cache the FileSystemWatcher, so that it resides in the Application and works for the lifetime of the Application.

---BRUCE---------------------------
If you use the application cache object you can place a cache dependency on the file, and the cache will release the object automatically if the file is changed.
 
K

Kevin Spencer

Yes. I would use a cahe dependency, as bruce suggested. If you do, you don't
want to store all the SML files as a single array. You would cache each
individually. If the file changes, the cached object is removed. You would
therefore have to include code that checks to see whether the particular XML
file is cached before attempting to get it. If it is cached, it is fetched
from the cache. If not, the file is opened, parsed, and put into the cache,
and THEN it is fectched from the cache.

I would also recommend that you only cache each XML file as needed, since
they will be removed individually, and must be replaced individually. IOW,
wait until you receive a request for a given XML file prior to caching that
one file.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Greg Collins [MVP]" <Greg.Collins_AT_InfoPathDev.com> wrote in message
So if I understand you both correctly I could do the following (please
excuse my lack of .NET experience and correct anything you need to):

1. The first time the decodeImage.aspx page is hit for a particular XML
file, decode the entire list of images, placing each one into an array which
is then stored in an Application Cache object in the Cache Collection. This
object can be named and referenced using the absolute path of the URL to the
XML file being decoded (minus any forbidden characters).

2. I can somehow create a link between the Application Cache object and the
XML file itself so that when the XML file is modified, the Cache object is
automatically removed from the Collection, thus signaling me to reload the
file, decode the images again, and recreate the Cache object.

3. Any subsequent requests for an image would grab the appropriate image
from the image array Cache object and return it to the calling Web page.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com


========================================
1. Can I store the XmlNodeList object and restore it for use the next time?
a. If not, is there any advantage to storing the XML in the variable
over having it reloaded?

---KEVIN---------------------------
The Application and Application Cache are Collections, pure and simple.
Well, the Cache is a specialized type of Collection, but it is, underneath
the specialization (extra methods, fields, etc) a Collection. They are, in
essence, Name and Object Collections.

As everything in .Net is an object, you can store anything in these
Collections, and use them just as you would any object in any Collection.

The advantage of storing your XML in the Collection is the saving of IO
processing and the processing involved in reading the XML from the file into
an object. So, yes, there is an advantage in terms of performance.

---BRUCE---------------------------
there is one difference between the application cache and the application
collections. if memory usage gets high, entries in the cache will
automatically be removed.


========================================
2. What is the max size for an Application variable?

---KEVIN---------------------------
AFAIK, there is no maximum size, other than memory capacity. At least, I've
never run into one. And I have put a LOT of data in the Cache before (dozens
of MB).


========================================
4. What actually happens when that size limit has been reached?

---KEVIN---------------------------
I would imagine an "out of memory" exception, but that's just a guess.

---BRUCE---------------------------
if you look in machine.config/web.config, there is a setting for the max
amount of memory asp.net will use (usually 60% of real memory). if asp.net
goes over this number, its recycled (this will lose inproc sessions).


========================================
5. Once each image have been decoded, are they cached on the server for the
Web page to use, or will the Web page always and forever call in to redecode
the image each time?
a. If so, I'd like to know my alternatives.
b. If not, how do I know when to release that variable?


---KEVIN---------------------------
If you put them into a Collection, such as Application or Cache, they are
cached. How do you know when to release that variable? Well, it's not a
variable, it's a member object of a Collection. Using the Cache, you can
tell the Cache when to remove the object, or you can remove it yourself.

If these XML documents are needed for the lifetime of the Application, you
can do that as well. No harm done. When the Application ends, the Collection
is automatically released.


========================================
6. How do I find out when the XML file has been updated so that I know to
update the Application variable?


---KEVIN---------------------------
You could use a FileSystemWatcher to watch for changes in the folder
containing the files, and have it respond to them. You could even cache the
FileSystemWatcher, so that it resides in the Application and works for the
lifetime of the Application.

---BRUCE---------------------------
If you use the application cache object you can place a cache dependency on
the file, and the cache will release the object automatically if the file is
changed.
 
G

Greg Collins [MVP]

Yep! Right on top of that one! I had the same thoughts!

Thanx for sharing that info... it helps a lot! And it makes me feel like I'm actually starting to understand a little of this.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



Yes. I would use a cahe dependency, as bruce suggested. If you do, you don't
want to store all the SML files as a single array. You would cache each
individually. If the file changes, the cached object is removed. You would
therefore have to include code that checks to see whether the particular XML
file is cached before attempting to get it. If it is cached, it is fetched
from the cache. If not, the file is opened, parsed, and put into the cache,
and THEN it is fectched from the cache.

I would also recommend that you only cache each XML file as needed, since
they will be removed individually, and must be replaced individually. IOW,
wait until you receive a request for a given XML file prior to caching that
one file.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Greg Collins [MVP]" <Greg.Collins_AT_InfoPathDev.com> wrote in message
So if I understand you both correctly I could do the following (please
excuse my lack of .NET experience and correct anything you need to):

1. The first time the decodeImage.aspx page is hit for a particular XML
file, decode the entire list of images, placing each one into an array which
is then stored in an Application Cache object in the Cache Collection. This
object can be named and referenced using the absolute path of the URL to the
XML file being decoded (minus any forbidden characters).

2. I can somehow create a link between the Application Cache object and the
XML file itself so that when the XML file is modified, the Cache object is
automatically removed from the Collection, thus signaling me to reload the
file, decode the images again, and recreate the Cache object.

3. Any subsequent requests for an image would grab the appropriate image
from the image array Cache object and return it to the calling Web page.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com


========================================
1. Can I store the XmlNodeList object and restore it for use the next time?
a. If not, is there any advantage to storing the XML in the variable
over having it reloaded?

---KEVIN---------------------------
The Application and Application Cache are Collections, pure and simple.
Well, the Cache is a specialized type of Collection, but it is, underneath
the specialization (extra methods, fields, etc) a Collection. They are, in
essence, Name and Object Collections.

As everything in .Net is an object, you can store anything in these
Collections, and use them just as you would any object in any Collection.

The advantage of storing your XML in the Collection is the saving of IO
processing and the processing involved in reading the XML from the file into
an object. So, yes, there is an advantage in terms of performance.

---BRUCE---------------------------
there is one difference between the application cache and the application
collections. if memory usage gets high, entries in the cache will
automatically be removed.


========================================
2. What is the max size for an Application variable?

---KEVIN---------------------------
AFAIK, there is no maximum size, other than memory capacity. At least, I've
never run into one. And I have put a LOT of data in the Cache before (dozens
of MB).


========================================
4. What actually happens when that size limit has been reached?

---KEVIN---------------------------
I would imagine an "out of memory" exception, but that's just a guess.

---BRUCE---------------------------
if you look in machine.config/web.config, there is a setting for the max
amount of memory asp.net will use (usually 60% of real memory). if asp.net
goes over this number, its recycled (this will lose inproc sessions).


========================================
5. Once each image have been decoded, are they cached on the server for the
Web page to use, or will the Web page always and forever call in to redecode
the image each time?
a. If so, I'd like to know my alternatives.
b. If not, how do I know when to release that variable?


---KEVIN---------------------------
If you put them into a Collection, such as Application or Cache, they are
cached. How do you know when to release that variable? Well, it's not a
variable, it's a member object of a Collection. Using the Cache, you can
tell the Cache when to remove the object, or you can remove it yourself.

If these XML documents are needed for the lifetime of the Application, you
can do that as well. No harm done. When the Application ends, the Collection
is automatically released.


========================================
6. How do I find out when the XML file has been updated so that I know to
update the Application variable?


---KEVIN---------------------------
You could use a FileSystemWatcher to watch for changes in the folder
containing the files, and have it respond to them. You could even cache the
FileSystemWatcher, so that it resides in the Application and works for the
lifetime of the Application.

---BRUCE---------------------------
If you use the application cache object you can place a cache dependency on
the file, and the cache will release the object automatically if the file is
changed.
 
G

Greg Collins [MVP]

Actually I do have a question. I think I know the answer, but I need to be absolutely sure.

Currently I'm using Cache.Insert() -- Is this an Application level or Session level Cache? As far as I can tell there's only 1 Cache object and it's Application level, but if I'm misguided on that, I want to make sure I'm using the Application Cache and not the Session Cache.

Thanx again in advance!

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



Yes. I would use a cahe dependency, as bruce suggested. If you do, you don't
want to store all the SML files as a single array. You would cache each
individually. If the file changes, the cached object is removed. You would
therefore have to include code that checks to see whether the particular XML
file is cached before attempting to get it. If it is cached, it is fetched
from the cache. If not, the file is opened, parsed, and put into the cache,
and THEN it is fectched from the cache.

I would also recommend that you only cache each XML file as needed, since
they will be removed individually, and must be replaced individually. IOW,
wait until you receive a request for a given XML file prior to caching that
one file.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Greg Collins [MVP]" <Greg.Collins_AT_InfoPathDev.com> wrote in message
So if I understand you both correctly I could do the following (please
excuse my lack of .NET experience and correct anything you need to):

1. The first time the decodeImage.aspx page is hit for a particular XML
file, decode the entire list of images, placing each one into an array which
is then stored in an Application Cache object in the Cache Collection. This
object can be named and referenced using the absolute path of the URL to the
XML file being decoded (minus any forbidden characters).

2. I can somehow create a link between the Application Cache object and the
XML file itself so that when the XML file is modified, the Cache object is
automatically removed from the Collection, thus signaling me to reload the
file, decode the images again, and recreate the Cache object.

3. Any subsequent requests for an image would grab the appropriate image
from the image array Cache object and return it to the calling Web page.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com


========================================
1. Can I store the XmlNodeList object and restore it for use the next time?
a. If not, is there any advantage to storing the XML in the variable
over having it reloaded?

---KEVIN---------------------------
The Application and Application Cache are Collections, pure and simple.
Well, the Cache is a specialized type of Collection, but it is, underneath
the specialization (extra methods, fields, etc) a Collection. They are, in
essence, Name and Object Collections.

As everything in .Net is an object, you can store anything in these
Collections, and use them just as you would any object in any Collection.

The advantage of storing your XML in the Collection is the saving of IO
processing and the processing involved in reading the XML from the file into
an object. So, yes, there is an advantage in terms of performance.

---BRUCE---------------------------
there is one difference between the application cache and the application
collections. if memory usage gets high, entries in the cache will
automatically be removed.


========================================
2. What is the max size for an Application variable?

---KEVIN---------------------------
AFAIK, there is no maximum size, other than memory capacity. At least, I've
never run into one. And I have put a LOT of data in the Cache before (dozens
of MB).


========================================
4. What actually happens when that size limit has been reached?

---KEVIN---------------------------
I would imagine an "out of memory" exception, but that's just a guess.

---BRUCE---------------------------
if you look in machine.config/web.config, there is a setting for the max
amount of memory asp.net will use (usually 60% of real memory). if asp.net
goes over this number, its recycled (this will lose inproc sessions).


========================================
5. Once each image have been decoded, are they cached on the server for the
Web page to use, or will the Web page always and forever call in to redecode
the image each time?
a. If so, I'd like to know my alternatives.
b. If not, how do I know when to release that variable?


---KEVIN---------------------------
If you put them into a Collection, such as Application or Cache, they are
cached. How do you know when to release that variable? Well, it's not a
variable, it's a member object of a Collection. Using the Cache, you can
tell the Cache when to remove the object, or you can remove it yourself.

If these XML documents are needed for the lifetime of the Application, you
can do that as well. No harm done. When the Application ends, the Collection
is automatically released.


========================================
6. How do I find out when the XML file has been updated so that I know to
update the Application variable?


---KEVIN---------------------------
You could use a FileSystemWatcher to watch for changes in the folder
containing the files, and have it respond to them. You could even cache the
FileSystemWatcher, so that it resides in the Application and works for the
lifetime of the Application.

---BRUCE---------------------------
If you use the application cache object you can place a cache dependency on
the file, and the cache will release the object automatically if the file is
changed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top