{"id":23498177,"url":"https://github.com/vpro/jsr107-magnolia","last_synced_at":"2025-04-15T16:15:46.240Z","repository":{"id":43278572,"uuid":"51753272","full_name":"vpro/jsr107-magnolia","owner":"vpro","description":"A ComponentConfigurer for the Magnolia CMS, which enables JSR107 caching by annotations.","archived":false,"fork":false,"pushed_at":"2024-08-14T09:11:38.000Z","size":537,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-15T16:15:39.071Z","etag":null,"topics":["jsr-107","magnolia","magnolia-cache","magnolia-cms","magnolia-component"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vpro.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-15T12:13:07.000Z","updated_at":"2024-08-14T09:11:42.000Z","dependencies_parsed_at":"2022-08-25T20:41:53.582Z","dependency_job_id":null,"html_url":"https://github.com/vpro/jsr107-magnolia","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpro%2Fjsr107-magnolia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpro%2Fjsr107-magnolia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpro%2Fjsr107-magnolia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpro%2Fjsr107-magnolia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vpro","download_url":"https://codeload.github.com/vpro/jsr107-magnolia/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249105471,"owners_count":21213535,"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":["jsr-107","magnolia","magnolia-cache","magnolia-cms","magnolia-component"],"created_at":"2024-12-25T05:28:52.825Z","updated_at":"2025-04-15T16:15:46.223Z","avatar_url":"https://github.com/vpro.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"= jsr107-magnolia\n\nimage:https://github.com/vpro/jsr107-magnolia/workflows/build/badge.svg?[Build Status,link=https://github.com/vpro/jsr107-magnolia/actions?query=workflow%3Abuild]\nimage:https://img.shields.io/maven-central/v/nl.vpro/jsr107-magnolia.svg?label=Maven%20Central[Maven Central,link=https://search.maven.org/search?q=g:%22nl.vpro%22%20AND%20a:%22jsr107-magnolia%22]\nimage:http://www.javadoc.io/badge/nl.vpro/jsr107-magnolia.svg?color=blue[javadoc,link=http://www.javadoc.io/doc/nl.vpro/jsr107-magnolia]\nimage:https://codecov.io/gh/vpro/jsr107-magnolia/branch/master/graph/badge.svg[codecov,link=https://codecov.io/gh/vpro/jsr107-magnolia]\nimage:https://img.shields.io/nexus/s/https/oss.sonatype.org/nl.vpro/jsr107-magnolia.svg[snapshots,link=https://oss.sonatype.org/content/repositories/snapshots/nl/vpro/jsr107-magnolia/]\n\n\nSee\n\n- https://www.magnolia-cms.com/\n- https://github.com/jsr107\n\nAfter installation, you can cache the result of any method of any guice managed bean by adding the `@CacheResult` annotation.\n\n[source,java]\n----\n@CacheResult(cacheName = \"CinemaUtil-sortedMovies\")\npublic List\u003cMap.Entry\u003cMovie, Set\u003cRoleType\u003e\u003e\u003e sortedMovies(Person person) {\n   ...\n}\n----\n\nIn this case in the magnolia cache configuration automaticly a cache 'CinemaUtil-sortedMovies' will appear.\n\n== Possible cache values\n\nThe cache values may be `null` and `Optional`. This implementation will arrange that no nulls are stored in the underlying magnolia cache. If the value is `Optional`, the value of the `Optional` will be serialized.\n\nNon serializable values are only possible if the underlying eh-cache is configured not to store to disk.\n\n== Model classes\n\nSadly, https://jira.magnolia-cms.com/browse/MAGNOLIA-6601[\"model classes are not instantiated by guice, but by Magnolia itself\"], so they cannot be proxied by guice.\n\n== Installation\n\nDownload the most recent jar from: https://oss.sonatype.org/content/repositories/snapshots/nl/vpro/jsr107-magnolia and install it like you'd normally would.\n\nOr you can add this to your pom.xml\n\n[source,xml]\n----\n\u003cdependency\u003e\n  \u003cgroupId\u003enl.vpro\u003c/groupId\u003e\n  \u003cartifactId\u003ejsr107-magnolia\u003c/artifactId\u003e\n  \u003cversion\u003e1.19\u003c/version\u003e\n\u003c/dependency\u003e\n----\n\n=== Configuration\n\nFor versions older then 1.14 caches were configured like so in the JCR-tree:\nimage:cache-config.png?raw=true[cache configuration]\nFrom 1.14 onwards Magnolia 5.5.4 uses ehcache3 so the configuration has changed and looks like this:\nimage:cache-config-ehcache3.png?raw=true[cache configuration]\n\nCache-configurations can be automaticly created using tasks on the version handler of your module.\nE.g. like this:\n\n[source,java]\n----\n@Slf4j\npublic class CinemaVersionHandler extends DefaultModuleVersionHandler {\n\n    @Override\n    protected List\u003cTask\u003e getBasicInstallTasks(InstallContext installContext) {\n        List\u003cTask\u003e tasks = super.getBasicInstallTasks(installContext);\n        tasks.addAll(CreateConfigurationTasks.createConfigurationTasks(CinemaUtilWithCaching.class));\n        log.info(\"Created tasks {}\", tasks);\n        return tasks;\n    }\n}\n----\n\nDefault settings could be configured using the `nl.vpro.magnolia.jsr107.DefaultCacheSettings` annotation:\n\n[source,java]\n----\n    @CacheResult(cacheName = \"CinemaUtil-scheduleForChannel\")\n    @DefaultCacheSettings(blockingTimeout = 30000)\n    List\u003cScheduleItem\u003e scheduleForChannel(String channel, LocalDate date) {\n        log.info(\"Getting movies for  {} {}\", channel, date);\n        MediaSearch search = new MediaSearch();\n        ....\n----\n\nIf you use an 'exception cache' too, you may want to configure this separately. You need to wrap a `@nl.vpro.magnolia.jsr107.Defaults` then.\n\n[source,java]\n----\n @CacheResult(cacheKeyGenerator = ImageCacheKey.class, cacheName = ASSET_LINKS_CACHE, exceptionCacheName = ASSET_LINKS_CACHE + \"-exceptions\")\n    @Defaults(\n        overrideOnUpdate = true,\n        exceptionCacheSettings = @DefaultCacheSettings(maxElementsInMemory = 200, timeToLiveSeconds = 300),\n        cacheSettings = @DefaultCacheSettings(maxElementsInMemory = 2000, timeToLiveSeconds = 3600)\n    )\n    @Override\n   public String getAssetLink(Image image, String variation) {\n\n----\n\nActually the code can also be accessed if you want to configure a cache programmaticly for some other reason. This more or less eliminates the need to configure cache outside code altogether.\nThe cache settings are in this way still visible in the JCR-tree, and can be modified and viewed via JMX, but they can be maintained in the code of your application.\n\n[source,java]\n----\n       // Create browser cache for api clients\n        setInstallOrUpdateTask(CreateCacheConfigurationTask.builder()\n            .name(CACHE)\n            .settings(CacheSettings.builder()\n                .eternal(true)\n                .overflowToDisk(true)\n                .diskSpoolBufferSizeMB(500)\n                .maxElementsInMemory(200)\n                .diskExpiryThreadInterval(Duration.ofHours(24))\n            )\n            .overrideOnUpdate(true)\n            .build());\n\n----\n\n== MgnlCacheManager\n\nThe `nl.vpro.magnolia.jsr107.MgnlCacheManager` implementation of `javax.cache.CacheManager` contains a few utilities which may come in useful when interacting with caches. E.g. utilities to get existing values from the caches, or to retrieve all keys, which can be used when activily refreshing entries in the cache (e.g. in conjection with `@javax.cache.annotation.CachePut`)\n\nA `MgnlCacheManager` can simply be obtained using `@Inject`.\n\n== Cache Event Listening\n\nSince version 1.16 we will also support cache listening. E.g.\n\n[source,java]\n----\n    @Inject\n    public MediaPlayerPageCache(\n        Provider\u003cVtkUtil\u003e vtkUtil,\n        ServerConfiguration serverConfiguration,\n        Provider\u003cMgnlCacheManager\u003e mgnlCacheManager,\n        @Named(SystemEventBus.NAME) EventBus systemEventBus\n) {\n        this.vtkUtil = vtkUtil;\n        this.serverConfiguration = serverConfiguration;\n        this.mgnlCacheManager = mgnlCacheManager;\n        systemEventBus.addHandler(ModulesStartedEvent.class, this::registerCacheEntryListener);\n    }\n\n    protected void registerCacheEntryListener(ModulesStartedEvent event) {\n        log.info(\"{}\", event);\n        mgnlCacheManager.get().getCache(CACHE_NAME).registerCacheEntryListener(new MutableCacheEntryListenerConfiguration\u003c\u003e(\n            new FactoryBuilder.SingletonFactory\u003c\u003e(new Listener()),\n            new FactoryBuilder.SingletonFactory\u003c\u003e(e -\u003e true),\n            false,\n            true));\n    }\n\n----\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvpro%2Fjsr107-magnolia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvpro%2Fjsr107-magnolia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvpro%2Fjsr107-magnolia/lists"}