Typo3 USER / userFunc and caching - caching

Ist there a way to set the maximal cache time for a USER object? (not sure if its really called object..)
The only thing i found was COA_GO - which is COA with user defined cache time - but the update to the latest revision is about two years old, which makes me hope that there is a similar core feature which made it obsolete...
/optimism off
if its not possible at all an example of how to leverage Typo3's internal cache would also solve most of my problems.
just had a look at class.t3lib_cache_manager.php, and... i don't really get it... was expecting something similar to apc...
Thanks in advance for any hint or suggestion!

Take a look at the new cObj Cache (Forge) and the blog article explaining how it works.
It basically registers a new stdWrap property which can contain a lifetime:
5 = TEXT
5 {
cache.key = mycurrenttimestamp
cache.tags = tag_a,tag_b,tag_c
cache.lifetime = 3600
data = date : U
strftime = %H:%M:%S
}

Related

Drupal State API - set key expired time

I am new to Drupal 8. I have found Drupal state API for cache mechanism. Can I set key expire time also with below statement?
\Drupal::state()->set('key','value');
Source : https://www.drupal.org/docs/8/api/state-api/overview
Here I am able to set key but I want to clear it after 60 minutes.
Is there any other cache mechanism I can use?
Any suggestion would be helpful.
Thanks in advance.
Instead of using State directly, you can use your own wrapper that uses the KeyValueExpirableFactoryInterface. See the Drupal docs for more about the KeyValueStore API.
Example:
$kvStorage = \Drupal::service('keyvalue.expirable')->get('my_collection_name');
$kvStorage->setWithExpire('my_key', 'my_value', time() + 3600);
Also, this article from Palantir has a good overview of the various data-storage APIs in Drupal 8 and what they are best for.
The other answer is incorrect. You specify the length of time in seconds from the current request. If you call time(), you're telling Drupal to store the value for a very, very, very long time.
// Get the key value collection
$kv_store = \Drupal::service('keyvalue.expirable')->get('my_module_name');
// Get the value or null
$token = $kv_store->get('token', null);
// If no value, set the value
if (!$token) {
$kv_storage->setWithExpire('token', 'my_token', 3600);
}

Compare new field value with old before save

I am building a Ruby Sinatra app with Datamapper as the ORM. I have come across a point that I can't find a decent solution and thought to hit StackOverflow for a solution.
I am needing to compare the old value of a filed with the new value entered by the user to do a small computation.
For example
car = Listing.all(type: :car).first
car.price # 200
car.price = 100
car.save # ~> discount = ( 200 - 100 / 200 ) * 100 ~= 50% - alert watchers
How can I find the old value within the modal?
I have an idea to abstract all modals with custom classes. This will make such operation possible. But wonder if it will add complexity unnecessarily.
Thanks in advance.
You can pull out the old value via model.original_attributes. Something like this should work for your case:
car = Listing.all(type: :car).first
car.price = 100
old_price = car.original_attributes[Listing.properties[:price]] # => 200
You should be able to put that in a before save hook and run your calculations and notifications from there.
HTH :)
(BTW I tested this with DM 1.2.1. I imagine that is the version you are using as well since the DM project is kind of dead-ish these days, but just so you should be aware)

Creating Attribute set is taking time because of “initFromSkeleton”

I have written a script to create attribute set and attribute from csv and it worked fine on my localhost but after uploading it to server I found that it is taking so much time to do the job even with 1 entry. So I was debugging it and I found out that "initFromSkeleton" is taking time.
$entityTypeId = Mage::getModel('eav/entity')
->setType('catalog_product')
->getTypeId(); // 4 - Default
$newSet = Mage::getModel('eav/entity_attribute_set');
$newSet->setEntityTypeId($entityTypeId);
$newSet->setAttributeSetName($setName);
$newSet->save();
$newSet->initFromSkeleton($entityTypeId);
$newSet->save();
I don't know what to do because to build new attribute based on default attribute set I have to write this initFromSkeleton. While searching google I found this link. But it understood from there.
Could any one has done this before. Please help me out. Thanks in advance
Disable automatic updating of indexes to improve performance.Change the index update mode to manual.

Adding an extension to the blog post pages on liferay

My problem is i want to add '.html' extension to my every blog post. For example right now i have a blog post url 'http://www.indu.com/blog/-/blogs/creating-a-custom-portlet-in-liferay' and what i want is 'http://www.indu.com/blog/-/blogs/creating-a-custom-portlet-in-liferay.html'
I would be grateful if any one can help?
I wonder why would you want this.
Anyways, I think you can change the urlTitle field of BlogsEntry and append .html to the string. May be use a service-wrapper-hook to append .html to the urlTitle whenever a blog is created or updated.
Or you can even use a ModelListener if it exists for BlogsEntry hook to update the blog's urlTitle by using onCreate & onUpdate methods.
Edit
The urlTitle field is present in the BlogsEntry table.
You can access this in java with the following methods:
BlogsEntry blog = BlogsEntryLocalServiceUtil.getBlogsEntry(90989); // retrieves the blog-entry
String blogUrlTitle = blog.getUrlTitle();
blog.setUrlTitle(blogUrlTitle + ".html"); // this would set the string
You can have a check for the blogUrlTitle so that you don't have repeated .html appended to the string:
if (!blogUrlTitle.contains(".html")) { // append only if the title does not contain `.html`
blog.setUrlTitle(blogUrlTitle + ".html");
}
You can refine your code as you like, the above is just a guide-line.
As a side-note, I would always try to reason with the client why they want something, this helps not only to fend-off bad-change-requests but also helps in giving an alternative to the client (which is less taxing on the developers like us ;-) ). In most cases this helps to understand the client's business better & provide better returns.

Amazon S3 REST library : how to get a link to a ressource that nevers expires?

To retrieve a url for a ressource on a bucket i use :
S3Object.url_for('beluga_baby.jpg', 'marcel_molina')
By default links expires after 5 minutes. Is it possible to ask for a link that never expires ?
I think i could set an expiration date far in the future but it seems kind of ugly...
doomsday = Time.mktime(2038, 1, 18).to_i
S3Object.url_for('beluga_baby.jpg',
'marcel',
:expires => doomsday)
P.S: I use the ruby library but i guess the question applies to all languages(?)
Thanks for your help,
Vincent
There is no way to get a link that never expires for private files.
Your solution of setting a far future expiry date is the correct way to do this.

Resources