I know of several ways to have a random image that is updated by each page request, but I need hints on how to have an image that is updated only once a day, that is, all visitors will see the same image on the same day. The only way I can think of at the moment is to have a folder with selected pictures, named for example as the day number of the month (i.e. 1,2,...,28), and then randomly choose the image source name as the day name.
Unless Umbraco (which I'm new to) can expire cache at a certain time there maybe problems with the above solution, depending on how important the timing is.
I assume that if you cache the macro for 24 hours, it will be only get re-cached when someone hits the page after the previous cache expires.
Therefore if no-one visits your site until 10am after the cache expires then it won't expire the next day till 10am etc.etc.
Plus doesn't publishing something in Umbraco invalidate the cache too?
(This could be completly wrong I'm just thinking about it from a.NET perspective)
I'm trying some very simple code to display an "image of the day" in a user control by caching the image url of a randomly chosen image with an absolute expiration date/time of YM(D+1) 00:00:01 and cacheitempriority set to notremovable. Still it lasts for, at the most, about 12 hours and is removed from cache. This is in a shared environment. Are there better ways (probably are) to do this?
You can use DateTime.Now.Date.Ticks as seed for "random number generator constructor" (I don't know class name from head). Then it should return same random number whole day.
Random picture of the day
Hi all,
I know of several ways to have a random image that is updated by each page request, but I need hints on how to have an image that is updated only once a day, that is, all visitors will see the same image on the same day. The only way I can think of at the moment is to have a folder with selected pictures, named for example as the day number of the month (i.e. 1,2,...,28), and then randomly choose the image source name as the day name.
Any suggestions please?
Regards
Use xslt to select the random picture,
Cache the macro that uses the xslt
Add a key with the image and date to the cache and recreate it if the date (from one day to another) changes
just my two cents
Thomas
As Thomas is suggesting you should make a comparison on date to make it change automatically.
/Jan
Ok, thanks guys. Should I have a user control to do this, or can this be done from Umbraco?
Regards
You can implement an xslt extension you can use then in xslt
Thomas
I believe that you would also be able to do it using http://our.umbraco.org/wiki/reference/umbracolibrary/formatdatetime
/Jan
Unless Umbraco (which I'm new to) can expire cache at a certain time there maybe problems with the above solution, depending on how important the timing is.
I assume that if you cache the macro for 24 hours, it will be only get re-cached when someone hits the page after the previous cache expires.
Therefore if no-one visits your site until 10am after the cache expires then it won't expire the next day till 10am etc.etc.
Plus doesn't publishing something in Umbraco invalidate the cache too?
(This could be completly wrong I'm just thinking about it from a.NET perspective)
Resuming an old thread :)
I'm trying some very simple code to display an "image of the day" in a user control by caching the image url of a randomly chosen image with an absolute expiration date/time of YM(D+1) 00:00:01 and cacheitempriority set to notremovable. Still it lasts for, at the most, about 12 hours and is removed from cache. This is in a shared environment. Are there better ways (probably are) to do this?
Thanks in advance.
Synsat
You can use DateTime.Now.Date.Ticks as seed for "random number generator constructor" (I don't know class name from head). Then it should return same random number whole day.
Petr
Sound like a good idea Petr, thanks.
is working on a reply...