Refresh cache for imagecontrol

thread: 4 messages  |  last: a year ago  |  started: sunday, march 28, 2010, 4:15 am pdt


#1  |  kentpachi (France, EU) France
Sunday, March 28, 2010, 4:15 AM PDT

Hi people,

I need some help with QImageControl

Each time a member upload a picture the old one is replaced by the new one. The thing is that they do have the samename.

membre with id 5

will upload 5.jpg each time but the pic might be different.

Qimagecontrol cache check if a cache exists for this imagename. Which is the case as the user used to have a pic before. But the pic is not the same anymore.

So how to ask imagecontrol to check for instance if its the same size to create again the cache.

Another work around wouldbe to suffix with stamp the picture name. Then at each upload it would be 5_2322322.jpg for instance. This will work as the name will be different but what will happens with old pics.

I will have to remove from cache only not used picture.

Also cleaning the whole cache would not be interesting as it'll cache again all pics for all user even if only one have changed his pic.

Third solution one cache folder per user, i don't know the efficiency of this method does anyone has implemented it ?

What are performances for this ?

Thanks to all for any resopnse.

#2  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Monday, March 29, 2010, 7:45 AM PDT

one cache folder per user might not be a bad idea actually -- there should be little-to-no performance issue with it.

However, depending on how many users you have, you might want to go to a two-level hierarchy.  For linux-based OS's, they typically recommend that you keep any folder to have something like < 10,000 (you might want to check?) items, files OR folders.  So depending on how many you're expecting to have, now might be a good time to do a two-level hierarchy... where you can do something like

$strCacheFolderName = '/path/to/cache/folder/' . ($intId % 10000) . '/' . $intId;

That way, you in essence get room for 10000 * 10000 = 100 Million IDs before running into issues with the limit.

You can of course easily then go to a third-level if you need 10 Billion, etc.

#3  |  kentpachi (France, EU) France
Tuesday, March 30, 2010, 1:34 PM PDT

Thank you mike

that's clever i've implemented this and i think it's working.

Just to confirm i've done some tests

and i understood things this way telle me if i'm wrong :

members with ids from 1 to 9999
will create 9999 folders

then the 10 000 member will be in folder 0

10 001 => folder 1
19 999 => folder 9999

20 000 = > 0

and so on is that right ?


Another point, i need to delete the cached file, according to this i need the cachefilename which is a md5 hash of the serialized form. Quite hard to guess.
ImageConrol or FileControl should have an attribute to get te cachefilename (there's one called CacheFilename but used only when rendering the picture in RenderAsImgSrc)

Regards


#4  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Thursday, April 1, 2010, 12:41 PM PDT

Hmm... that's a good point.  It's likely that we will want to implement functionality in QImageControl to “delete” or “force re-generate” a cache image...

Feel free and open up a ticket in the issue tracker for this.

But in the meantime, if you use the option above, you can just manually delete the file because you are explicitly specifying the folder to save the cached file to.

So if you have a cached version of image #5, simply delete the image file (regardless of the name) out of the cache folder for that image id... hope that makes sense...



Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.