GORM (grails) - cache blob image or something else - caching

Let's say I have a domain class
class Profile{
String name
byte[] logo
}
and a controller:
class ImageController {
def renderImage ={
def image = Profile.get(params.id).logo
if (image) {
response.setContentLength(image.length)
response.getOutputStream().write(image)
} else {
response.sendError(404)
}
}
}
and a gsp:
<img width="48"
height="48"
src="${createLink(controller: 'image', action: 'renderImage', id: 1)}">
Ok so so far so good. The image renders fine and I am happy. However, since the gsp snippet is part of my main layout the image is rendered each time I reload a page.
My question: is there a way to cache this image (blob mysql)? I have 2nd level caching turned on etc. But I am not sure if the image is cached or not. How would you do this?
thanks.

Add static mapping = { cache true } to your Profile domain class to turn on caching. As long as you fetch the Profile objects with get(id), it'll use the cached version. If you're using a more complicated query, you'll need to let grails know the query is cacheable too.
See the Caching section in the Grails manual. Also, it can be helpful to turn on hibernate SQL logging to confirm the objects are cached.

Related

Typo3: Disable caching for viewhelper inside gridelements fluid template

I have an inherited typo3 website (running 10.4.31 now) that must have been created in 2016 or so, and it contains a custom ViewHelper that has some time-based logic (you can set a countdown and once it's elapsed, something is supposed to happen). The problem is that it only works if you're logged in, in dev environments or when you have the cache disabled globally.
the setup is something like this:
TypoScript:
tt_content.gridelements_pi1.20.10.setup {
37 < lib.gridelements.defaultGridSetup
37 {
cObject = FLUIDTEMPLATE
cObject {
file = EXT:myext/Resources/Private/Templates/gridelements/ce/countdown.html
}
}
}
Template
<div class="countdown-container">
{namespace content=My\Ext\ViewHelpers}
<content:Countdown time="{data.flexform_date}" image="{data.flexform_image}" />
</div>
and then the aforementioned custom Viewhelper.
The question is: Is there any way to tell typo3 to execute the ViewHelper's PHP code every time instead of caching? I have googled a lot, but none of the solutions I've found work. Things I have tried include:
adding <f:cache.disable /> to the HTML template: no effect
throwing StopCompilingException from the ViewHelper's compile method: no effect (but I can see that the exception gets thrown and caught)
adding COA_INT or USER_INT to the typoscript: no effect (I can see them in the object browser, but honestly I don't know if I put them in the right place)
You can disable the cache for this specific Gridelement by using a COA_INT container as surrounding cObject:
tt_content.gridelements_pi1.20.10.setup {
37 < lib.gridelements.defaultGridSetup
37 {
cObject = COA_INT
cObject {
10 = FLUIDTEMPLATE
10.file = EXT:myext/Resources/Private/Templates/gridelements/ce/countdown.html
}
}
}

when I use If isset($_FILES['something'] I can't access my controller array in my view in codeigniter?

when I load same view in If Else condition I cant access my view as data in view control !! For Example (This code is for Edit Profile pic)
if(isset($_FILES['file1']))
{
//here some code to upload photo and resize it
$data2['avtar'] = $this->upload_model->update_photo($source) //Retriving data from model
$this->load->view('profile_view',$data2,TRUE);
}
else
{
$this->load->view('profile_view');
}
I can't access $data2['avtar'] value in my view !! when I remove third parameter true I can see its value in view using var_dump($avtar) but it loads two view of same page and mixed in one another. I want to access only image path to view whom I can put in <img src=""> in my view. so tell me whats the problem?
From the Docs
If you set the parameter to true (boolean) it will return data. The
default behavior is false, which sends it to your browser. Remember to
assign it to a variable if you want the data returned:
$string = $this->load->view('myfile', '', true);
By examining the provided code, I can not see how it loads two view of same page. Maybe your code is in a loop.
You can also use AJAX to update the image.

ExtJS - Handling Session Management

I want to know how i can save page data.first i will tell how my application works.
I have a container and i am adding panels to this dynamically.
something like this
--container
--add panel_1
---want to add panel_2 ? remove panel_1 and add panel_2 in that place
My problem is..Now i am planning to have a back button in panel 2..when user clicks ,will take him to panel_1 and i want to show what he entered...Please help me
have seen this (Extjs 4 Session Management)
I use an extra class with static members for holding data in MVC arch in ExtJS. So I save objects, arrays, vars etc in it from controller and use them later in project. Perhaps this help you as well. Save panel_1 object or data and goto panel_2, or viceversa
e.g.
Ext.define('MyApp.controller.Utility', {
statics : {
panel1: false,
panel2: false,
myFun : function() {
//some code
}
}
});
in any controller/view etc whenever you want to save an object or value, refer to this class but first add to require. .e.g.
var ut = MyApp.controller.Utility;
ut.panel1 = Ext.ComponentQuery.query('panel')[0];

Grails Webflow display image - flow scope

I have saved an image to a byte[] in a command object and wish to display it in the next stage of the createFlow webflow.
I am trying to steer clear of using the file system and / or database system for storing the image during the webflow.
Typically, to view the image, I would call renderImage from the gsp:
class ArtefactController {
def createFlow = {
............
}
def renderImage = {
def ArtefactInstance = Artefact.findById(params.id)
if(ArtefactInstance?.image) {
response.setContentLength(ArtefactInstance.image.length)
response.outputStream.write(ArtefactInstance.image)
}
else {
response.sendError(404)
}
}
however for the webflow when I try to call renderFlowImage from a gsp:
def renderFlowImage = {
if(flow.artefactCommand?.image) {
response.setContentLength(flow.artefactCommand.image.length)
response.outputStream.write(flow.artefactCommand.image)
}
else {
response.sendError(404)
}
}
The flow scope in not accessable.
Any suggestions?
I assume you're hitting the renderFlowImage action in your flow's view with a second http request via an img tag such as:
<img src="${createLink(action:'renderFlowImage')}" />
This won't work because, for one thing, you need to pass in a 'flowExecutionKey' which grails uses to match a request with a flow.
It is possible to work around this, but you might be better off just rendering the image during the rendering phase of your flow's next view with a data URI in the img tag. You could do this easily with the rendering plugin, which provides some handy tags (among other things) to render inline images using a data uri.
So in the next flow view, you could replace the existing img tag with a call to one of the rendering plugin's 'inline' tags:
<rendering:inlineJpeg bytes="${artefactCommand.image}" />
But be careful - there are some limitations to the data URI approach to be aware of (see http://www.7cynics.com/webdesign/css/css-inline-images-data-uri.html).

wicket image path without rewrite

I m trying to upload and show images.
I get the file, write it to docroot of glassfish application server, then
Image image = new Image("myimage","images/task.gif");
But i get <img wicket:id="myimage" src="resources/wickcat.MyPage/images/task.gif" />
Is there any way that wicket wont rewrite my src path? Even when i use an http://.... starting src, it writes resources/wickcat.MyPage/http://... which makes no sense at all.
I just need it to write "images/task.gif".
Any ideas?
There is two ways to do this.
Use <img src="images/task.gif" />. This is if you don't need reference to the component in the class.
Use ContextImage image = new ContextImage("myimage", "images/task.gif");. If you use the ContextImage component, the source will be relative to the Context root, you can even input a model as the relative path to the image.
The Image class assumes the image is a resource located in the classpath.
You could use a WebMarkupContainer with a SimpleAttributeModifier:
WebMarkupContainer img = new WebMarkupContainer("myimage")
.add(new SimpleAttributeModifier("src", "/images/task.gif"));
It will output the string as is, so you have complete control.
If it is used several times across the application, I'd recommend you to create a component encapsulating this behavior. Something like
public class MyImage extends WebMarkupContainer {
public MyImage(String id, String path) {
add(new SimpleAttributeModifier("src", path));
}
}

Resources