{"id":17347502,"url":"https://github.com/cryptiklemur/memcached-bundle","last_synced_at":"2025-04-14T20:46:04.295Z","repository":{"id":56941525,"uuid":"9773678","full_name":"cryptiklemur/memcached-bundle","owner":"cryptiklemur","description":"Memcached bundle for Symfony 2","archived":false,"fork":false,"pushed_at":"2017-12-20T15:05:11.000Z","size":124,"stargazers_count":13,"open_issues_count":3,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T21:49:09.835Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cryptiklemur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-30T15:15:09.000Z","updated_at":"2020-11-29T21:52:21.000Z","dependencies_parsed_at":"2022-08-21T07:50:23.709Z","dependency_job_id":null,"html_url":"https://github.com/cryptiklemur/memcached-bundle","commit_stats":null,"previous_names":["cryptiklemur/memcached-bundle","aequasi/memcached-bundle"],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cryptiklemur%2Fmemcached-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cryptiklemur%2Fmemcached-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cryptiklemur%2Fmemcached-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cryptiklemur%2Fmemcached-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cryptiklemur","download_url":"https://codeload.github.com/cryptiklemur/memcached-bundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248960709,"owners_count":21189987,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T16:48:59.201Z","updated_at":"2025-04-14T20:46:04.276Z","avatar_url":"https://github.com/cryptiklemur.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"memcached-bundle [![Build Status](https://travis-ci.org/aequasi/memcached-bundle.png?branch=master)](https://travis-ci.org/aequasi/memcached-bundle)\n================\n\n\n# THIS BUNDLE IS DEPRECATED\n\nMoving forward, use the [`php-cache`](http://www.php-cache.com) library\n\n\n## If you insist.....\n\n### Memcached Bundle for Symfony 2\n\nCreates a service in Symfony 2 that can also be used with doctrines `result_cache_driver` and `query_cache_driver`.\n\nThere is also functionality for having a key map stored in mysql. Basically, it stores the keys, the size of the value, how long the lifetime is, and when it should expire.\n\nShould work in all versions of symfony, and php 5.3\n\nRequires the php5-memcached extension (Works with amazons elasticache extension as well)\n\n### Requirements\n\n- PHP 5.3.x or 5.4.x\n- php5-memcached 1.x or 2.x (this is the PHP \"memcached\" extension that uses \"libmemcached\")\n- (Works with amazons elasticache extension as well)\n\n![screenshot](http://www.leaseweblabs.com/wp-content/uploads/2013/03/memcache_debug.png)\n\n### To Install\n\n```sh\n\tcomposer.phar require aequasi/memcached-bundle dev-master\n\t// Replace dev master with what ever version you want\n```\n\nAdd the bundle to app/AppKernerl.php\n\n```php\n$bundles(\n    ...\n       new Aequasi\\Bundle\\MemcachedBundle\\AequasiMemcachedBundle(),\n    ...\n);\n```\n\nThen add parameters (probably in config.yml) for your servers, and options\n\n```yml\naequasi_memcached:\n    clusters:\n        default:\n            prefix: 'result_' # Optional\n            persistent_id: cluser_1\n            hosts: \n              - { host: localhost, port: 11211, weight: 100 }\n            options:\n                compression: true\n                libketama_compatible: true\n                connect_timeout: 50\n                recv_timeout: 500000\n                send_timeout: 500000\n                poll_timeout: 50\n                retry_timeout: 5\n                no_block: true\n                server_failure_limit: 7\n                tcp_no_delay: true\n            keyMap:\n                enabled: %memcached.keymap.enabled%\n                connection: default\n```\n\nThere are also options that you can specify above. You can get the list of options by running\n\n```php\nphp app/console config:dump aequasi_memcached\n```\n\n#### Doctrine\n\nThis bundle allows you to use its services for Doctrine's caching methods of metadata, result, and query.\n\nIf you want doctrine to use this as the result and query cache, add this\n\n```yml\naequasi_memcached:\n    doctrine:\n        metadata:\n            cluster: default\n            entity_manager: default          # the name of your entity_manager connection\n            document_manager: default        # the name of your document_manager connection\n        result:\n            cluster: default\n            entity_manager: [default, read]  # you may specify multiple entity_managers\n        query:\n            cluster: default\n            entity_manager: default\n```\n\n#### Session\n\nThis bundle even allows you to store your session data in one of your memcache clusters. To enable:\n\n```yml\naequasi_memcached:\n    session:\n        cluster: default\n        prefix: \"session_\"\n        ttl: 7200\n```\n\n#### Anti Stampede\nTaken from Lws\\MemcacheBundle\n\nLet us examine a high traffic website case and see how Memcache behaves:\n\nYour cache is stored for 90 minutes. It takes about 3 second to calculate the cache value and 1 ms second to read from cache the cache value. You have about 5000 requests per second and that the value is cached. You get 5000 requests per second taking about 5000 ms to read the values from cache. You might think that that is not possible since 5000 \u003e 1000, but that depends on the number of worker processes on your web server Let's say it is about 100 workers (under high load) with 75 threads each. Your web requests take about 20 ms each. Whenever the cache invalidates (after 90 minutes), during 3 seconds, there will be 15000 requests getting a cache miss. All the threads getting a miss will start to calculate the cache value (because they don't know the other threads are doing the same). This means that during (almost) 3 seconds the server wont answer a single request, but the requests keep coming in. Since each worker has 75 threads (holding 100 x 75 connections), the amount of workers has to go up to be able to process them.\n\nThe heavy forking will cause extra CPU usage and the each worker will use extra RAM. This unexpected increase in RAM and CPU is called the 'dog pile' effect or 'stampeding herd' and is very unwelcome during peek hours on a web service.\n\nThere is a solution: we serve the old cache entries while calculating the new value and by using an atomic read and write operation we can make sure only one thread will receive a cache miss when the content is invalidated. The algorithm is implemented in AntiDogPileMemcache class in LswMemcacheBundle. It provides the getAdp() and setAdp() functions that can be used as replacements for the normal get and set.\n\nPlease note:\n\nAnti Stampede might not be needed if you have low amount of hits or when calculating the new value goes relatively fast.\nAnti Stampede might not be needed if you can break up the big calculation into smaller, maybe even with different timeouts for each part.\nAnti Stampede might get you older data than the invalidation that is specified. Especially when a thread/worker gets \"false\" for \"get\" request, but fails to \"set\" the new calculated value afterwards.\nAnti Stampede's \"getAdp\" and Anti Stampede \"setAdp\" are more expensive than the normal \"get\" and \"set\", slowing down all cache hits.\nAnti Stampede does not guarantee that the dog pile will not occur. Restarting Memcache, flushing data or not enough RAM will also get keys evicted and you will run into the problem anyway.\n\n### To Use\n\nYou can use the default memcached functions, doctrine's `useResultCache` and `useQueryCache`, or you can use the `cache` function. Heres an example\n\n```php\nuse Aequasi\\Bundle\\MemcachedBundle\\Cache\\AntiStampedeMemcached as Cache;\n\n/** @var $em \\Doctrine\\ORM\\EntityManager */\n$data = $this-\u003eget( 'memcached.default' )-\u003ecache(\n\t'somekey',\n\tfunction( ) use( $em, $color ) {\n\t\t$repo = $em-\u003egetRepository( 'AcmeDemoBundle:Fruit' );\n\t\treturn $repo-\u003efindBy( array( 'color' =\u003e $color ) );\n\t}, Cache::THIRTY_MINUTE\n);\n```\n\nThis will attempt to grab `somekey`. If it cant find it, it will run the closure, and cache it for 30 minutes, as `somekey`. You can use a closure here, or a callable, or even just a scalable type.\n\nThere are also three commands (might add more later), for getting, setting, and deleting items in cache.\n\n```sh\n\nphp app/console memcached:get cluster key\n\nphp app/console memcached:set cluster key value [lifetime=60]\n\nphp app/console memcached:delete cluster key\n\nphp app/console memcached:clear [cluster] # If cluster is specified, might not clear all the keys for the cluster. Uses http://www.php.net/manual/en/memcached.getallkeys.php\n\nphp app/console memcached:statistics cluster\n\nphp app/console memcached:initialize:keymap cluster (required if using the keymap)\n\n```\n\n### Need Help?\n\nCreate an issue if you've found a bug,\n\nor email me at aequasi@gmail.com\n\n\n[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/aequasi/memcached-bundle/trend.png)](https://bitdeli.com/free \"Bitdeli Badge\")\n\n[99]: http://www.github.com/aequasi/cache-bundle\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcryptiklemur%2Fmemcached-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcryptiklemur%2Fmemcached-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcryptiklemur%2Fmemcached-bundle/lists"}