dude9er — 2010-08-18T20:18:13-04:00 — #1
Is it possible to programmatically cache an image using VB code behind? If so, can someone lead me in the right direction?
imaginekitty — 2010-08-18T20:23:25-04:00 — #2
I suppose you could cache anything but why cache an image?
dude9er — 2010-08-22T13:02:29-04:00 — #3
I am using a masterpage and therefore the meta tag is in the header of that page and affects everything. Any way around this?
I really want to cut back on bandwidth for obvious reasons.
Any feedback would be great.
serenarules — 2010-08-20T12:20:00-04:00 — #4
Wow. I totally missunderstood that one from the beginning. Heh.
And those headers are extremely effective. I don't think there's really a way around it. If you use those, they affect everything.
I tend not to use them and let the user set caching options in their browser so everybody gets what they want.
serenarules — 2010-08-20T15:09:34-04:00 — #5
Correct me if I'm wrong OP, but it seems like your talking about the page bg, which you'e most likely set using css (inline or rel, doesn't matter).
What you might want to do is identify which pages in your app display static only, and those that display dynamic, then simply include the no-cache headers only on the dynamic pages. I believe you can use the Page object to access the meta tags, though I'm not certain, if you want to add them via code.
It's not a perfect, or elegent solution, but it will cut down on some of your bandwidth usage.
dude9er — 2010-08-20T11:59:39-04:00 — #6
I am using two meta tags
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
because the site loads data to run, this works to keep the data current for the user, but I want to be able to cache the background image of the site so they are not having to download it each time.
serenarules — 2010-08-18T22:21:36-04:00 — #7
Try using Session or HttpContext.Items collections (depending on how long you need to cache it). Also, try not to use them directly. Instead, write some session extension methods so you can set/get them in a typed fashion.
Public NotInheritable Class SessionExtensions
Private Sub New()
Public Shared Sub SetImage(session As HttpSessionStateBase, key As String, image As Byte())
session("Image:" & key) = image
Public Shared Function GetImage(session As HttpSessionStateBase, key As String) As Byte()
Return TryCast(session("Image:" & key), Byte())
Then simply import the namespace into your page class and call it like this:
byte data = Session.GetImage("MyImage");
This is, of course, assuming your storing it as a byte array. Alter the code otherwise.
chieftain — 2010-08-24T08:51:29-04:00 — #8
wwb_99 — 2010-08-24T07:35:01-04:00 — #9
How big is this background image to actually effect bandwidth outlays in 2010?
serenarules — 2010-08-22T13:44:42-04:00 — #10
In the master...
<asp:ContentPlaceHolder ID="TitlePlaceholder" runat="server" />
<asp:ContentPlaceHolder ID="HeadPlaceholder" runat="server" />
And then in your views...
<asp:Content ID="HeadContent" ContentPlaceHolderID="HeadPlaceholder" runat="server">
<!-- add metas here on the pages you want them -->
dude9er — 2010-08-23T17:33:39-04:00 — #11
I ended up creating two master pages one with the no-cache metas for the data pages and one without. Thanks for everyone's help.
john_betong — 2010-08-20T19:36:47-04:00 — #12
Can you give us the link to the page and no doubt there will be an abundance of posters offering how improvements.
john_betong — 2010-08-20T05:38:48-04:00 — #13
I have recently moved my thumbnails on a site to a sub-domain on the same site and the page loading appears significantly faster with the images popping up as and when they are loaded.
Check out this link: http://www.askapache.com/htaccess/apache-speed-subdomains.html
nightstalker — 2010-08-20T02:29:29-04:00 — #14
How do you want to cache the image? The bytes or what? It will not really make sense, as the user has to still download the file. Cache would need to be client side. Unless you are talking about a dynamic thumbnailer and you want to cache the output.
Just remember, caching images in this manner will not really help, as your site will tend to have more images than memory available for caching. Best is to use a combination of Memory and disk caching
mittineague — 2010-08-20T12:35:58-04:00 — #15
You could try sending the headers for individual files instead of doing the page.
I don't know how it would be done in .NET but it seems there should be some way to do it.