Cache Problem?

Hi All,

I’m getting crazy with this problem, I have no idea how to solve it, let me explain…

I have a grid where there is a list of images, in each row there is thumb as preview image and a button to crop to let the user crop the image. When the user crop the image I also generate a new thumb from the image already cropped and I overwrite the images by saving them with the same name.

After the image is cropped, I refresh the grid by renderPartial, the problem is that the thumb isn’t refreshed, I don’t know if it’s a cache problem or something like this because I save the image with the same name it had before. It only works if I refresh the entire page, the renderPartial works fine because I have tried to render other view and it works.

Here is my code:

Action




//Crop from the orginal file and save it in different folder

		    if( is_file( $originalFile ) ) {

			    $fileCropped = Yii::app()->phpThumb->create($originalFile);

			    $fileCropped->crop($cropX,$cropY,$cropW,$cropH);

					

			    $fileCropped->save($file);

                chmod( $file, 0777 );

			}	


			//Overwrite the current thumb with the one from the already cropped image

			if( is_file( $thumbFile ) ) {			

                $thumb=Yii::app()->phpThumb->create($file);

                $thumb->resize(80,80);						

                $thumb->save($thumbFile);			

			}

			

			echo $this->renderPartial('/postimage/_upload', array('model'=>$model->images, 'post_id'=>$model->id), true, false);



The script:




<script>

$('body').on('click', '#bt-crop', function(event){


		var form = $('#crop-form');

		var post = { };

		form.find('input').each(function(){

			var name = $(this).attr('name');

			var value = $(this).val();

			post[name] = value;

		});


		var opts = {

			url: $(this).attr('href'),

			data: post,

			cache: false, 

			async: true, 

			type: 'POST', 

			success: function(data){

                $('#upload-file-tmp').html(data);

				//document.location.reload();

			}

			,error: function(e){

				alert(e.responseText);				

			}

		}

		$.ajax(opts);

		event.preventDefault();

	});

</script>



The whole process works, except the thumb image isn’t refreshed and I don’t know why, I would really appreciate some help on this.

Thanks!

We can manage the caching in protected/config/main.php file

First check from which path the image is loaded. for example /assets/…

then add this line of code

‘clientScript’=>array(

     'scriptMap'=&gt;array(


          'your image path'=&gt;false,


     ),


),

hope this might solve your problem.

Thanks, the thing is that the path is dynamic, so I only know the path in runtime. I have realized that in Chrome it works, just sometimes not always, but in Firefox it never works. I don’t even know if it’s a cache problem or it’s related to another cause.