locked
Image Cache RRS feed

  • Question

  • User1519602350 posted

    I have stored all my website images in my DB. Each time i refresh it's taking long time to load. How can I cache the images?

    Thanks

    Tuesday, July 23, 2013 7:43 AM

Answers

  • User-306750178 posted

    Save all the images at a folder in your project is the good solution.

    OR

    Use the session variable to when you get images first time.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 23, 2013 7:47 AM
  • User895691971 posted

    Saving the images to the Database is not a good idea. Save the name of the image in Database but save the image file to the File System.

    This way, extracting image will be easy and also will be fast enough!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 25, 2013 11:33 AM

All replies

  • User-306750178 posted

    Save all the images at a folder in your project is the good solution.

    OR

    Use the session variable to when you get images first time.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 23, 2013 7:47 AM
  • User1519602350 posted

    How to use session variable for dynamic images?. Please advise me.

    Tuesday, July 23, 2013 7:49 AM
  • User38443587 posted

    Hello, here is a demo about how to save picture in session.

    protected void Page_Load(object sender, EventArgs e)
            {
                if (Session["xx"] == null)
                {
                    SqlConnection sqlConnection = new SqlConnection(@"Data Source=.\xx;Initial Catalog=ImageTest;Integrated Security=True");
                    sqlConnection.Open();
                    string comText = "Select ImageData from ImageTable";
                    SqlCommand sqlCommand = new SqlCommand(comText, sqlConnection);
                    SqlDataReader dr = sqlCommand.ExecuteReader();
                    dr.Read();
                    Session["xx"] = (byte[])dr[0];
                }
            }

    however, if the picture is large enouth, this method will occupy a lot of memory and it may also lead some problem in user experience. Most time save pictures in local and save the path in database is a prefer method. Thank you.

    Wednesday, July 24, 2013 5:21 AM
  • User895691971 posted

    Saving the images to the Database is not a good idea. Save the name of the image in Database but save the image file to the File System.

    This way, extracting image will be easy and also will be fast enough!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 25, 2013 11:33 AM