Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • synsat 30 posts 43 karma points
    Aug 21, 2009 @ 11:25
    synsat
    0

    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

  • Bert 128 posts 251 karma points
    Aug 21, 2009 @ 11:27
    Bert
    0

    Use xslt to select the random picture,

    Cache the macro that uses the xslt

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Aug 21, 2009 @ 11:28
    Thomas Höhler
    0

    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

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Aug 21, 2009 @ 11:33
    Jan Skovgaard
    0

    As Thomas is suggesting you should make a comparison on date to make it change automatically.

    /Jan

  • synsat 30 posts 43 karma points
    Aug 21, 2009 @ 12:46
    synsat
    0

    Ok, thanks guys. Should I have a user control to do this, or can this be done from Umbraco?

    Regards

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Aug 21, 2009 @ 14:03
    Thomas Höhler
    0

    You can implement an xslt extension you can use then in xslt

    Thomas

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Aug 21, 2009 @ 14:24
    Jan Skovgaard
    0

    I believe that you would also be able to do it using http://our.umbraco.org/wiki/reference/umbracolibrary/formatdatetime

    /Jan

  • Rich Green 2246 posts 4008 karma points
    Aug 21, 2009 @ 14:50
    Rich Green
    1

    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)

     

  • synsat 30 posts 43 karma points
    Apr 14, 2010 @ 20:27
    synsat
    0

    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

  • Petr Snobelt 923 posts 1535 karma points
    Apr 15, 2010 @ 09:43
    Petr Snobelt
    0

    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

  • synsat 30 posts 43 karma points
    Apr 15, 2010 @ 20:23
    synsat
    0

    Sound like a good idea Petr, thanks.

Please Sign in or register to post replies

Write your reply to:

Draft