Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by vexe · Feb 22, 2016 at 07:30 PM · serverwwwdownload

Always get older version of file when downloading it from server?

Greetings,

There's a text file on our server with some config/settings. I'm trying to download it and read the values in the game. Here's my download routine:

 IEnumerator DownloadRoutine()
 {
     string url = "http://path/to/directory/settings.txt";

     using (var www = new WWW(url))
     {
         yield return www;
         if (www.error != null)
             throw new Exception("WWW download had an error:" + www.error);

         print(www.text);
     }
 }

So I create the settings file with an initial version, say containing the line "data1 = value1" The download routine works perfectly, and on the 'print' I see the settings.

The problem is if I then change the settings file by adding another line "data2 = value2", I still get the previous version of the file so the printout prints "data1 = value1" as if I didn't add the second line.

I'm not an expert on networking/webstuff so I'm not sure what I'm missing.

I'm on Windows 7 Professional accessing the server and adding/modifying the files via WinSCP. There are options in it to clear cache but it doesn't seem to have any effect. So I'm not sure if the older values are being cached somehow or not...

Any ideas?

Thanks.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Magius96 · Feb 22, 2016 at 07:35 PM

I've had this issue before. Here's a simple solution to a difficult problem. Change your URL to include a random string.

 // Just create some random string here
 string randomString = new GUID.ToString();
 
 string url = string.Format("http://path/to/directory/settings.txt?c={0}", randomString);
 

The problem is that web servers cache data, so you have to kind of force it to ignore the cache settings. The random string causes it to do this because it now caches the results with the random string at the end.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vexe · Feb 22, 2016 at 08:22 PM 0
Share

Awesome! $$anonymous$$any thanks sir! What's the ?c= stand for? (the 'c' part). Also, shouldn't there be an option to tell the server not to cache the file? cause now with this solution the server caches multiple stuff cause of the random string (which I don't know if it's super bad or no)

avatar image Magius96 vexe · Feb 24, 2016 at 09:07 PM 0
Share

The 'c' can be anything you want there. If you are running your own server, then there should be a way to tell the server to not cache certain pages or anything at all. That is not done through code, but through the server's configurations.

The server caching multiple copies isn't going to hurt the server or affect its performance. Web servers have a set amount of cache space available to them, when that space gets filled, it simply starts clearing out the oldest cache items. Cached items also only exist in the cache for a set period of time, so its not like it's gonna fill up your memory or hard drive.

What we're doing with my method above is forcing the server to think that each request is supposed to have a different result by passing in query string parameters that are different each time. In this case, it doesn't matter what we call the parameter, though we're calling it 'c', and it doesn't matter what the value of that parameter is, as long as its different each time. On the server side, nothing is being done with the parameter that we're passing, nothing at all. But because its there it forces the server software to believe this is a different request than all the others so it sends you an updated copy of the file.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

36 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Localhost does not work after launching build from hosting 1 Answer

Getting a Code to Run at a Specific Time of Day Even if App is Off. 1 Answer

Downloading files in the Editor 2 Answers

where is the result of a www download stored? 1 Answer

Can I access previously downloaded textures? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges