/ / Symfony2 सरल परिणाम कैश? - php, कैशिंग, सिम्फनी

Symfony2 सरल परिणाम कैश? - PHP, कैशिंग, सिम्फनी

मुझे सिम्फनी में एक बहुत ही सरल कुंजी-मूल्य-कैश की आवश्यकता है। ऐसा कुछ, बिना किसी सिद्धांत या HTTP-caching के।

<?php
$cacheKey = "blabla";
if(!$cache->has($cacheKey)) {
// do some heavy work...
$cache->set($cacheKey, $heavyWorkResult);
}
$result = $cache->get($cacheKey);

क्या मैं इसे मैनुअल में याद करता हूं या मुझे एक और बंडल की आवश्यकता है?

उत्तर:

जवाब के लिए 2 № 1

आप गूगल क्यों नहीं करते? या देख लेना knpbundles.com और "कैश" के लिए वहां खोजें:

http://knpbundles.com/search?q=Cache

शायद यह आपकी आवश्यकताओं के लिए कुछ है:

https://github.com/winzou/CacheBundle

उपयोग:

$cache = $this->get("winzou_cache.apc");
// or
$cache = $this->get("winzou_cache.file");
// or
$cache = $this->get("winzou_cache.memcache");
// or
$cache = $this->get("winzou_cache.array");
// or
$cache = $this->get("winzou_cache.xcache");
// or
$cache = $this->get("winzou_cache.zenddata");
// or
$cache = $this->get("winzou_cache"); // in that case, it will use the default driver     defined in config.yml, see below

$cache->save("bar", array("foo", "bar"));

if ($cache->contains("bar")) {
$bar = $cache->fetch("bar");
}

$cache->delete("bar");

संपादित करें:</ Strong>

इसके लिए सत्र का उपयोग करना अच्छा नहीं है। सत्र प्रति उपयोगकर्ता है और कैश्ड मान साझा नहीं किए जा सकते। और जब आप सत्र का उपयोग करते हैं तो आपको क्रमांकन और अन्य समस्याओं के बारे में सोचना पड़ता है जब आप सत्र में जटिल वस्तु को संग्रहीत करते हैं।


उत्तर № 2 के लिए 1

मुझे लगता है कि आप इसका उपयोग कर सकते हैं https://github.com/doctrine/cache (स्टैंडअलोन में अब सिद्धांत द्वारा उपयोग की जाने वाली कैश प्रणाली)


उत्तर № 3 के लिए 1

मैंने LiipDoctrineCache का उपयोग किया है, हालांकि यह Doctrine कैश का उपयोग करता है, यह फ़ाइल सिस्टम और APC सहित - कई डेटा स्टोर का समर्थन करता है।

https://github.com/liip/LiipDoctrineCacheBundle

यहां मैं बाहरी API प्रतिक्रियाओं को कैश करने के लिए इसका उपयोग कैसे करूं:

$cache_driver = $container->get("liip_doctrine_cache.ns.YOUR_NAME");

if ($cache_driver->contains($cache_key)) {
return $this->cache_driver->fetch($cache_key);
}

// Do something expensive here...

$cache_driver->save($cache_key, "Mixed Data", strtotime("4 hours"));

जवाब के लिए 0 № 4

सिम्फनी प्रलेखन से:

use SymfonyComponentHttpFoundationSessionSession;

$session = new Session();
$session->start();

// set and get session attributes
$session->set("name", "Drak");
$session->get("name");

http://symfony.com/doc/master/components/http_foundation/sessions.html